From df6c31eac27e45aa8156a205bc04cc88a419169c Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 5 May 2024 18:15:37 +0330 Subject: [PATCH] ltable --- Back/Controllers/CustomerController.cs | 37 +++ Back/Features/CheckOnlineUser.cs | 2 +- Back/Program.cs | 1 + Back/Services/servCustomer.cs | 180 +++++++++++++++ Shared/DTOs/AddSubTicket.cs | 7 +- Shared/DTOs/Employee1.cs | 3 + Shared/DTOs/Features/ShowNameAttribute.cs | 9 + Shared/DTOs/ItemSerchGetCustomer.cs | 21 ++ Shared/DTOs/RCustomer.cs | 24 ++ Shared/DTOs/TestModel.cs | 19 ++ TaxPayerFull/CUSComponent/LTable.razor | 66 ++++++ TaxPayerFull/Pages/Sign-in.razor | 1 + TaxPayerFull/Pages/UserPanel/Customer.razor | 244 +++++++------------- 13 files changed, 451 insertions(+), 163 deletions(-) create mode 100644 Back/Controllers/CustomerController.cs create mode 100644 Back/Services/servCustomer.cs create mode 100644 Shared/DTOs/Features/ShowNameAttribute.cs create mode 100644 Shared/DTOs/ItemSerchGetCustomer.cs create mode 100644 Shared/DTOs/RCustomer.cs create mode 100644 Shared/DTOs/TestModel.cs create mode 100644 TaxPayerFull/CUSComponent/LTable.razor diff --git a/Back/Controllers/CustomerController.cs b/Back/Controllers/CustomerController.cs new file mode 100644 index 0000000..bf85d9c --- /dev/null +++ b/Back/Controllers/CustomerController.cs @@ -0,0 +1,37 @@ +using Back.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Shared.DTOs; + +namespace Back.Controllers +{ + [Route("api/[controller]")] + [Authorize] + [ApiController] + public class CustomerController : ControllerBase + { + private readonly CheckPermission _checkPermission; + private readonly servUser _servUser; + private readonly servCustomer _servCus; + public CustomerController(CheckPermission checkPermission, servUser servUser, servCustomer servCus) + { + + _checkPermission = checkPermission; + _servUser = servUser; + _servCus = servCus; + } + [HttpPost("GetAll")] + public async Task>> GetAll(ItemSerchGetCustomer itemSerch) + { + var claim = HttpContext.User.Claims.First(c => c.Type == "UserID"); + var UserID = claim.Value; + var user = await _servUser.GetUserByUserID(Convert.ToInt32(UserID)); + + if (!await _checkPermission.AllowSYSGetCustomer(Convert.ToInt32(UserID), user.RolUsers.First().CompanyID)) return Forbid( "شما دسترسی به خواندن اطلاعات مشتری را نداربد"); + + return Ok(await _servCus.GetCustomers(user.RolUsers.First().CompanyID, itemSerch)); + + + } + } +} diff --git a/Back/Features/CheckOnlineUser.cs b/Back/Features/CheckOnlineUser.cs index 505cbb1..69dba46 100644 --- a/Back/Features/CheckOnlineUser.cs +++ b/Back/Features/CheckOnlineUser.cs @@ -29,7 +29,7 @@ namespace Back.Features { servUser _servUser = (servUser)httpContext.RequestServices.GetService(typeof(servUser)); var user = _servUser.GetUserByUserID(UserID).Result; - if (user != null && user.Token==accessToken) + if ((user != null && user.Token==accessToken) || httpContext.GetEndpoint().DisplayName.Contains("BaseController")) await _next(httpContext); else httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized; diff --git a/Back/Program.cs b/Back/Program.cs index 8164f53..aafc6d3 100644 --- a/Back/Program.cs +++ b/Back/Program.cs @@ -37,6 +37,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(c => new mpNuget.RestClient("09119660045", "C54S2")); diff --git a/Back/Services/servCustomer.cs b/Back/Services/servCustomer.cs new file mode 100644 index 0000000..3a4f454 --- /dev/null +++ b/Back/Services/servCustomer.cs @@ -0,0 +1,180 @@ +using Back.Common; +using Back.Data.Contracts; +using Back.Data.Models; +using Microsoft.EntityFrameworkCore; +using Shared.DTOs; + +namespace Back.Services +{ + public class servCustomer + { + private readonly IAsyncRepository _repoCus; + private readonly CheckPermission _checkPermission; + public servCustomer(IAsyncRepository repoCus, CheckPermission checkPermission) + { + _repoCus = repoCus; + _checkPermission = checkPermission; + + } + public async Task?> GetCustomers(int CompanyID, ItemSerchGetCustomer itemSerch) + { + #region AdvancedSearch + var invok = _repoCus + .Get(w => w.CompanyID == CompanyID && !w.IsDeleted); + //foreach (InputObj item in inputObjs) + // invok = invok.Where(ExMethod.GetFunc(item.Param, item.Value)); + if (!string.IsNullOrEmpty(itemSerch.ZipCode)) + invok = invok.Where(w=>w.ZipCode.Contains(itemSerch.ZipCode)); + + if (!string.IsNullOrEmpty(itemSerch.Phone)) + invok = invok.Where(w => w.Phone.Contains(itemSerch.Phone)); + + if (!string.IsNullOrEmpty(itemSerch.MeliCode)) + invok = invok.Where(w => w.MeliCode.Contains(itemSerch.MeliCode)); + + if (itemSerch.CustomerType.HasValue) + invok = invok.Where(w => w.CustomerType==itemSerch.CustomerType); + + if (itemSerch.ID.HasValue) + invok = invok.Where(w => w.ID == itemSerch.ID); + + if (!string.IsNullOrEmpty(itemSerch.EconomicCode)) + invok = invok.Where(w => w.EconomicCode.Contains(itemSerch.EconomicCode)); + #endregion + //----------------------- + return await invok.Select(s=>new RCustomer() + { + // Address = s.Address, + CustomerType = s.CustomerType.GetEnumDisplayName(), + EconomicCode = s.EconomicCode, + // Email =s.Email, + FullName = s.FullName, + ID = s.ID, + // Info = s.Info, + Phone=s.Phone, + // BranchID = s.BranchID, + // MeliCode = s.MeliCode, + // ZipCode = s.ZipCode , + // PassportNumber=s.PassportNumber, + // CompanyID=s.CompanyID + }) + .Paging(itemSerch.PageIndex, itemSerch.PageSize); + } + //public async Task GetCustomerByCustomerID(int CustomerID, int CompanyID) + //{ + // return await _repositores.GET() + // .Where(w => w.ID == CustomerID && w.CompanyID==CompanyID && !w.IsDeleted).FirstOrDefaultAsync(); + //} + //public async Task GetCustomerByCustomerID(int CustomerID) + //{ + // return await _repositores.GET() + // .Where(w => w.ID == CustomerID && !w.IsDeleted).FirstOrDefaultAsync(); + //} + //public async Task ExistCustomerByCustomerID(int CustomerID, int CompanyID) + //{ + // return await _repositores.GET() + // .AnyAsync(w => w.ID == CustomerID && w.CompanyID == CompanyID && !w.IsDeleted); + //} + //public async Task GetCustomerByCustomerIDByDTO(int CustomerID) + //{ + // return await _repositores.GET() + // .Where(w => w.ID == CustomerID && !w.IsDeleted) + // .Select(s => new CUCustomer() + // { + // Address = s.Address, + // CustomerType = s.CustomerType, + // EconomicCode = s.EconomicCode, + // Email = s.Email, + // FullName = s.FullName, + // ID = s.ID, + // Info = s.Info, + // Phone = s.Phone, + // BranchID = s.BranchID, + // MeliCode = s.MeliCode, + // ZipCode = s.ZipCode, + // PassportNumber = s.PassportNumber, + // //CompanyID = s.CompanyID + // }) + // .FirstOrDefaultAsync(); + //} + //public async Task AddORUpdateCustomer(Customer item) + //{ + // try + // { + // SysLog log = new SysLog() + // { + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer", + // Value ="*"+ JsonConvert.SerializeObject(item), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + // }; + // _contextMongodb.InsertItem(log); + + // if (item.ID == null || item.ID == 0) + // { + // var ret = await _repositores.ADD(item); + // _checkPermission.ExtensionofAccess(item.CompanyID, 5, "-1"); + // return item; + // } + // else + // { + // return await _repositores.UPDATE(item); + // } + // } + // catch (Exception ex) + // { + // SysLog log = new SysLog() + // { + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/AddORUpdateCustomer", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + // }; + // _contextMongodb.InsertItem(log); + // return null; + // } + + //} + //public async Task DeleteCustomer(Customer item) + //{ + + // try + // { + // item.IsDeleted = true; + // _repositores.UPDATE(item); + // SysLog log = new SysLog() + // { + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer", + // Value = JsonConvert.SerializeObject(item.ID), + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "User" + // }; + // _contextMongodb.InsertItem(log); + // return true; + // } + // catch (Exception ex) + // { + // SysLog log = new SysLog() + // { + // TraceIdentifierID = _httpContextAccessor.HttpContext.TraceIdentifier, + // Datetime = DateTime.Now.ConvertMiladiToShamsi(), + // Method = $"{_httpContextAccessor.HttpContext.Request.Method}/{this.GetType().FullName}/DeleteCustomer", + // Value = ex.Message, + // Route = _httpContextAccessor.HttpContext.Request.Path, + // Type = "catch" + // }; + // _contextMongodb.InsertItem(log); + // return false; + + // } + //} + + + } +} diff --git a/Shared/DTOs/AddSubTicket.cs b/Shared/DTOs/AddSubTicket.cs index 5de7e83..3e8155e 100644 --- a/Shared/DTOs/AddSubTicket.cs +++ b/Shared/DTOs/AddSubTicket.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.ComponentModel.DataAnnotations; namespace Shared.DTOs { diff --git a/Shared/DTOs/Employee1.cs b/Shared/DTOs/Employee1.cs index 1616762..d2ace5a 100644 --- a/Shared/DTOs/Employee1.cs +++ b/Shared/DTOs/Employee1.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -8,7 +9,9 @@ namespace Shared.DTOs { public class Employee1 { + [Display(Name ="شناسه")] public int Id { get; set; } + [Display(Name = "نام")] public string Name { get; set; } public string Designation { get; set; } public DateOnly DOJ { get; set; } diff --git a/Shared/DTOs/Features/ShowNameAttribute.cs b/Shared/DTOs/Features/ShowNameAttribute.cs new file mode 100644 index 0000000..11c552c --- /dev/null +++ b/Shared/DTOs/Features/ShowNameAttribute.cs @@ -0,0 +1,9 @@ +namespace Shared.DTOs +{ + + [AttributeUsage(AttributeTargets.Property)] + public class ShowNameAttribute : Attribute + { + public string Name = ""; + } +} diff --git a/Shared/DTOs/ItemSerchGetCustomer.cs b/Shared/DTOs/ItemSerchGetCustomer.cs new file mode 100644 index 0000000..3d00ee5 --- /dev/null +++ b/Shared/DTOs/ItemSerchGetCustomer.cs @@ -0,0 +1,21 @@ +using Shared.DTOs.Serch; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs +{ + public class ItemSerchGetCustomer : IFildGlobalItemSerch + { + public int? ID { get; set; } + public CustomerType? CustomerType { get; set; } + public string? EconomicCode { get; set; } + public string? Phone { get; set; } + public string? MeliCode { get; set; } + public string? ZipCode { get; set; } + public int PageIndex { get; set; } = 1; + public int PageSize { get; set; } = 5; + } +} diff --git a/Shared/DTOs/RCustomer.cs b/Shared/DTOs/RCustomer.cs new file mode 100644 index 0000000..6625ac2 --- /dev/null +++ b/Shared/DTOs/RCustomer.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs +{ + public class RCustomer + { + [Display(Name ="شناسه")] + public int ID { get; set; } + [Display(Name = "نام کامل")] + public string FullName { get; set; } + [Display(Name = "نوع مشتری")] + public string CustomerType { get; set; } + [Display(Name = "تلفن")] + public string Phone { get; set; } + [Display(Name = "کد اقتصادی")] + public string? EconomicCode { get; set; } + + } +} diff --git a/Shared/DTOs/TestModel.cs b/Shared/DTOs/TestModel.cs new file mode 100644 index 0000000..bc86b7e --- /dev/null +++ b/Shared/DTOs/TestModel.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Shared.DTOs +{ + public class TestModel + { + [Display(Name = "شناسه")] + public int ID { get; set; } + [Display(Name = "نام")] + public string Name { get; set; } + [Display(Name = "آدرس")] + public string Address { get; set; } + } +} diff --git a/TaxPayerFull/CUSComponent/LTable.razor b/TaxPayerFull/CUSComponent/LTable.razor new file mode 100644 index 0000000..effc844 --- /dev/null +++ b/TaxPayerFull/CUSComponent/LTable.razor @@ -0,0 +1,66 @@ +@using System.Reflection +@using System.ComponentModel.DataAnnotations +@using Shared.DTOs +@typeparam T + +
+
+
+
+
+
+
+ + + + @{ + PropertyInfo[] properties = typeof(T).GetProperties(); + foreach (var item in properties) + { + if (item.GetCustomAttributes(typeof(DisplayAttribute), false).Length > 0) + { + + } + + } + } + + + + @{ + foreach (var item in ModelinComponent) + { + + @{ + properties = item.GetType().GetProperties(); + foreach (PropertyInfo property in properties) + { + if (property.CustomAttributes.Any(w => w.AttributeType.Name == "DisplayAttribute")) + { + + } + + } + } + + } + } + +
+ @item.CustomAttributes.Where(w => w.AttributeType.Name == "DisplayAttribute").Select(s => s.NamedArguments.Where(w => w.MemberName == "Name").Select(ss => ss.TypedValue.Value).First()).First().ToString() +
@property.GetValue(item, null)
+
+
+ + +
+
+
+
+
+ +@code { + [Parameter] + public List ModelinComponent { get; set; } = new List(); + +} diff --git a/TaxPayerFull/Pages/Sign-in.razor b/TaxPayerFull/Pages/Sign-in.razor index a9cbcef..893a389 100644 --- a/TaxPayerFull/Pages/Sign-in.razor +++ b/TaxPayerFull/Pages/Sign-in.razor @@ -230,6 +230,7 @@ private async Task OnLoginClick() { + _hc.DefaultRequestHeaders.Clear(); var request = await _hc.PostAsJsonAsync("User/authenticate", Model); if (request.IsSuccessStatusCode) { diff --git a/TaxPayerFull/Pages/UserPanel/Customer.razor b/TaxPayerFull/Pages/UserPanel/Customer.razor index 895a005..897a766 100644 --- a/TaxPayerFull/Pages/UserPanel/Customer.razor +++ b/TaxPayerFull/Pages/UserPanel/Customer.razor @@ -1,5 +1,9 @@ @page "/Customer" +@using Front.Services @using Shared.DTOs +@using Front.CUSComponent +@using Shared.DTOs.Serch +@inject HttpClientController hc; مشتری @* search *@
@@ -58,170 +62,98 @@
-@* data *@ +@* alert *@
-
-
-
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
پروژهمشتریکاربرانوضعیتعملکردها
پروژه انگولارآلبرت کوک -
    -
  • - Avatar -
  • -
  • - Avatar -
  • -
  • - Avatar -
  • -
-
فعال - -
پروژه ری اکتبری هانتر -
    -
  • - Avatar -
  • -
  • - Avatar -
  • -
  • - Avatar -
  • -
-
تکمیل شد - -
پروژه وی جی استرور بیکر -
    -
  • - Avatar -
  • -
  • - Avatar -
  • -
  • - Avatar -
  • -
-
برنامه ریزی شده - -
پروژه بوت استرپجری میلتون -
    -
  • - Avatar -
  • -
  • - Avatar -
  • -
  • - Avatar -
  • -
-
درانتظار - -
-
-
+ - -
-
-
-
+@* data *@ +@if (request != null) +{ + + + @* pagination *@ + + + +} + @layout PanelLayout @code { - private IEnumerable? employees; + // alert + AlertColor alertColor = AlertColor.Primary; + IconName alertIconName = IconName.CheckCircleFill; + bool Hidealert = true; + string alertMessage = ""; - private async Task> EmployeesDataProvider(GridDataProviderRequest request) + protected override async Task OnParametersSetAsync() { - if (employees is null) // pull employees only one time for client-side filtering, sorting, and paging - employees = GetEmployees(); // call a service or an API to pull the employees - - return await Task.FromResult(request.ApplyTo(employees)); + if (PageIndex == null) PageIndex = 1; + await LoadCus(PageIndex.Value); + await base.OnParametersSetAsync(); } + [Parameter, SupplyParameterFromQuery] + public int? PageIndex { get; set; } - private IEnumerable GetEmployees() - { - return new List - { - new Employee1 { Id = 107, Name = "Alice", Designation = "AI Engineer", DOJ = new DateOnly(1998, 11, 17), IsActive = true }, - new Employee1 { Id = 103, Name = "Bob", Designation = "Senior DevOps Engineer", DOJ = new DateOnly(1985, 1, 5), IsActive = true }, - new Employee1 { Id = 106, Name = "John", Designation = "Data Engineer", DOJ = new DateOnly(1995, 4, 17), IsActive = true }, - new Employee1 { Id = 104, Name = "Pop", Designation = "Associate Architect", DOJ = new DateOnly(1985, 6, 8), IsActive = false }, - new Employee1 { Id = 105, Name = "Ronald", Designation = "Senior Data Engineer", DOJ = new DateOnly(1991, 8, 23), IsActive = true }, - new Employee1 { Id = 102, Name = "Line", Designation = "Architect", DOJ = new DateOnly(1977, 1, 12), IsActive = true }, - new Employee1 { Id = 101, Name = "Daniel", Designation = "Architect", DOJ = new DateOnly(1977, 1, 12), IsActive = true }, - new Employee1 { Id = 108, Name = "Zayne", Designation = "Data Analyst", DOJ = new DateOnly(1991, 1, 1), IsActive = true }, - new Employee1 { Id = 109, Name = "Isha", Designation = "App Maker", DOJ = new DateOnly(1996, 7, 1), IsActive = true }, - }; - } + public Shared.DTOs.PagingDto? request { get; set; } } +@functions { + private void ShowSuccessAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Success; + alertIconName = IconName.CheckCircleFill; + alertMessage = msg; + } + + private void ShowDangerAlert(string msg) + { + Hidealert = false; + alertColor = AlertColor.Danger; + alertIconName = IconName.ExclamationTriangleFill; + alertMessage = msg; + } + public async Task LoadCus(int pi) + { + var rsp = await hc.Post("Customer/GetAll", new ItemSerchGetCustomer() + { + PageIndex=pi + }); + if (rsp.IsSuccessStatusCode) + { + request = await rsp.Content.ReadFromJsonAsync>(); + } + else if(rsp.StatusCode==System.Net.HttpStatusCode.Forbidden) + { + ShowDangerAlert("شما دسترسی به خواندن اطلاعات مشتری را نداربد"); + } + else + { + ShowDangerAlert("خطایی در اجرای عملیات رخ داده"); + } + } +} \ No newline at end of file