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, CustomerTypeTitle = 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, CustomerType= s.CustomerType // 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; // } //} } }