Exemplo n.º 1
0
        public async Task <int> Count(CustomerTypeFilter filter)
        {
            IQueryable <CustomerTypeDAO> CustomerTypes = DataContext.CustomerType.AsNoTracking();

            CustomerTypes = DynamicFilter(CustomerTypes, filter);
            return(await CustomerTypes.CountAsync());
        }
Exemplo n.º 2
0
        public async Task <ActionResult <List <CustomerGrouping_CustomerTypeDTO> > > FilterListCustomerType([FromBody] CustomerGrouping_CustomerTypeFilterDTO CustomerGrouping_CustomerTypeFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerTypeFilter CustomerTypeFilter = new CustomerTypeFilter();

            CustomerTypeFilter.Skip      = 0;
            CustomerTypeFilter.Take      = 20;
            CustomerTypeFilter.OrderBy   = CustomerTypeOrder.Id;
            CustomerTypeFilter.OrderType = OrderType.ASC;
            CustomerTypeFilter.Selects   = CustomerTypeSelect.ALL;
            CustomerTypeFilter.Id        = CustomerGrouping_CustomerTypeFilterDTO.Id;
            CustomerTypeFilter.Code      = CustomerGrouping_CustomerTypeFilterDTO.Code;
            CustomerTypeFilter.Name      = CustomerGrouping_CustomerTypeFilterDTO.Name;

            List <CustomerType> CustomerTypes = await CustomerTypeService.List(CustomerTypeFilter);

            List <CustomerGrouping_CustomerTypeDTO> CustomerGrouping_CustomerTypeDTOs = CustomerTypes
                                                                                        .Select(x => new CustomerGrouping_CustomerTypeDTO(x)).ToList();

            return(CustomerGrouping_CustomerTypeDTOs);
        }
        public async Task <List <TicketReport_CustomerTypeDTO> > FilterListCustomerType([FromBody] TicketReport_CustomerTypeFilterDTO TicketReport_CustomerTypeFilterDTO)
        {
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerTypeFilter CustomerTypeFilter = new CustomerTypeFilter();

            CustomerTypeFilter.Skip      = 0;
            CustomerTypeFilter.Take      = 20;
            CustomerTypeFilter.OrderBy   = CustomerTypeOrder.Id;
            CustomerTypeFilter.OrderType = OrderType.ASC;
            CustomerTypeFilter.Selects   = CustomerTypeSelect.ALL;
            CustomerTypeFilter.Id        = TicketReport_CustomerTypeFilterDTO.Id;
            CustomerTypeFilter.Name      = TicketReport_CustomerTypeFilterDTO.Name;
            CustomerTypeFilter.Code      = TicketReport_CustomerTypeFilterDTO.Code;

            List <CustomerType> CustomerTypes = await CustomerTypeService.List(CustomerTypeFilter);

            List <TicketReport_CustomerTypeDTO> TicketReport_CustomerTypeDTOs = CustomerTypes
                                                                                .Select(x => new TicketReport_CustomerTypeDTO(x)).ToList();

            return(TicketReport_CustomerTypeDTOs);
        }
Exemplo n.º 4
0
        public async Task <List <CustomerType> > List(CustomerTypeFilter CustomerTypeFilter)
        {
            try
            {
                List <CustomerType> CustomerTypes = await UOW.CustomerTypeRepository.List(CustomerTypeFilter);

                return(CustomerTypes);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerTypeService));
            }
            return(null);
        }
Exemplo n.º 5
0
        public async Task <int> Count(CustomerTypeFilter CustomerTypeFilter)
        {
            try
            {
                int result = await UOW.CustomerTypeRepository.Count(CustomerTypeFilter);

                return(result);
            }
            catch (Exception ex)
            {
                await Logging.CreateSystemLog(ex, nameof(CustomerTypeService));
            }
            return(0);
        }
Exemplo n.º 6
0
        public async Task <List <CustomerType> > List(CustomerTypeFilter filter)
        {
            if (filter == null)
            {
                return(new List <CustomerType>());
            }
            IQueryable <CustomerTypeDAO> CustomerTypeDAOs = DataContext.CustomerType.AsNoTracking();

            CustomerTypeDAOs = DynamicFilter(CustomerTypeDAOs, filter);
            CustomerTypeDAOs = DynamicOrder(CustomerTypeDAOs, filter);
            List <CustomerType> CustomerTypes = await DynamicSelect(CustomerTypeDAOs, filter);

            return(CustomerTypes);
        }
Exemplo n.º 7
0
 public async Task <CustomerTypeFilter> ToFilter(CustomerTypeFilter filter)
 {
     if (filter.OrFilter == null)
     {
         filter.OrFilter = new List <CustomerTypeFilter>();
     }
     if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
     {
         return(filter);
     }
     foreach (var currentFilter in CurrentContext.Filters)
     {
         CustomerTypeFilter subFilter = new CustomerTypeFilter();
         filter.OrFilter.Add(subFilter);
         List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
         foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
         {
             if (FilterPermissionDefinition.Name == nameof(subFilter.Id))
             {
                 subFilter.Id = FilterBuilder.Merge(subFilter.Id, FilterPermissionDefinition.IdFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Code))
             {
                 subFilter.Code = FilterBuilder.Merge(subFilter.Code, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(subFilter.Name))
             {
                 subFilter.Name = FilterBuilder.Merge(subFilter.Name, FilterPermissionDefinition.StringFilter);
             }
             if (FilterPermissionDefinition.Name == nameof(CurrentContext.UserId) && FilterPermissionDefinition.IdFilter != null)
             {
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.IS.Id)
                 {
                 }
                 if (FilterPermissionDefinition.IdFilter.Equal.HasValue && FilterPermissionDefinition.IdFilter.Equal.Value == CurrentUserEnum.ISNT.Id)
                 {
                 }
             }
         }
     }
     return(filter);
 }
Exemplo n.º 8
0
        public async Task <bool> ValidateId(CustomerType CustomerType)
        {
            CustomerTypeFilter CustomerTypeFilter = new CustomerTypeFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerType.Id
                },
                Selects = CustomerTypeSelect.Id
            };

            int count = await UOW.CustomerTypeRepository.Count(CustomerTypeFilter);

            if (count == 0)
            {
                CustomerType.AddError(nameof(CustomerTypeValidator), nameof(CustomerType.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Exemplo n.º 9
0
        public async Task <ActionResult> Export([FromBody] CustomerGrouping_CustomerGroupingFilterDTO CustomerGrouping_CustomerGroupingFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            MemoryStream memoryStream = new MemoryStream();

            using (ExcelPackage excel = new ExcelPackage(memoryStream))
            {
                #region CustomerGrouping
                var CustomerGroupingFilter = ConvertFilterDTOToFilterEntity(CustomerGrouping_CustomerGroupingFilterDTO);
                CustomerGroupingFilter.Skip = 0;
                CustomerGroupingFilter.Take = int.MaxValue;
                CustomerGroupingFilter      = await CustomerGroupingService.ToFilter(CustomerGroupingFilter);

                List <CustomerGrouping> CustomerGroupings = await CustomerGroupingService.List(CustomerGroupingFilter);

                var CustomerGroupingHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Code",
                        "Name",
                        "CustomerTypeId",
                        "ParentId",
                        "Path",
                        "Level",
                        "StatusId",
                        "Description",
                    }
                };
                List <object[]> CustomerGroupingData = new List <object[]>();
                for (int i = 0; i < CustomerGroupings.Count; i++)
                {
                    var CustomerGrouping = CustomerGroupings[i];
                    CustomerGroupingData.Add(new Object[]
                    {
                        CustomerGrouping.Id,
                        CustomerGrouping.Code,
                        CustomerGrouping.Name,
                        CustomerGrouping.CustomerTypeId,
                        CustomerGrouping.ParentId,
                        CustomerGrouping.Path,
                        CustomerGrouping.Level,
                        CustomerGrouping.StatusId,
                        CustomerGrouping.Description,
                    });
                }
                excel.GenerateWorksheet("CustomerGrouping", CustomerGroupingHeaders, CustomerGroupingData);
                #endregion

                #region CustomerType
                var CustomerTypeFilter = new CustomerTypeFilter();
                CustomerTypeFilter.Selects   = CustomerTypeSelect.ALL;
                CustomerTypeFilter.OrderBy   = CustomerTypeOrder.Id;
                CustomerTypeFilter.OrderType = OrderType.ASC;
                CustomerTypeFilter.Skip      = 0;
                CustomerTypeFilter.Take      = int.MaxValue;
                List <CustomerType> CustomerTypes = await CustomerTypeService.List(CustomerTypeFilter);

                var CustomerTypeHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Code",
                        "Name",
                        "Description",
                        "StatusId",
                        "Used",
                        "RowId",
                    }
                };
                List <object[]> CustomerTypeData = new List <object[]>();
                for (int i = 0; i < CustomerTypes.Count; i++)
                {
                    var CustomerType = CustomerTypes[i];
                    CustomerTypeData.Add(new Object[]
                    {
                        CustomerType.Id,
                        CustomerType.Code,
                        CustomerType.Name,
                    });
                }
                excel.GenerateWorksheet("CustomerType", CustomerTypeHeaders, CustomerTypeData);
                #endregion
                #region Status
                var StatusFilter = new StatusFilter();
                StatusFilter.Selects   = StatusSelect.ALL;
                StatusFilter.OrderBy   = StatusOrder.Id;
                StatusFilter.OrderType = OrderType.ASC;
                StatusFilter.Skip      = 0;
                StatusFilter.Take      = int.MaxValue;
                List <Status> Statuses = await StatusService.List(StatusFilter);

                var StatusHeaders = new List <string[]>()
                {
                    new string[] {
                        "Id",
                        "Code",
                        "Name",
                    }
                };
                List <object[]> StatusData = new List <object[]>();
                for (int i = 0; i < Statuses.Count; i++)
                {
                    var Status = Statuses[i];
                    StatusData.Add(new Object[]
                    {
                        Status.Id,
                        Status.Code,
                        Status.Name,
                    });
                }
                excel.GenerateWorksheet("Status", StatusHeaders, StatusData);
                #endregion
                excel.Save();
            }
            return(File(memoryStream.ToArray(), "application/octet-stream", "CustomerGrouping.xlsx"));
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Import(IFormFile file)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            CustomerTypeFilter CustomerTypeFilter = new CustomerTypeFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = CustomerTypeSelect.ALL
            };
            List <CustomerType> CustomerTypes = await CustomerTypeService.List(CustomerTypeFilter);

            StatusFilter StatusFilter = new StatusFilter
            {
                Skip    = 0,
                Take    = int.MaxValue,
                Selects = StatusSelect.ALL
            };
            List <Status> Statuses = await StatusService.List(StatusFilter);

            List <CustomerGrouping> CustomerGroupings = new List <CustomerGrouping>();

            using (ExcelPackage excelPackage = new ExcelPackage(file.OpenReadStream()))
            {
                ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets.FirstOrDefault();
                if (worksheet == null)
                {
                    return(Ok(CustomerGroupings));
                }
                int StartColumn          = 1;
                int StartRow             = 1;
                int IdColumn             = 0 + StartColumn;
                int CodeColumn           = 1 + StartColumn;
                int NameColumn           = 2 + StartColumn;
                int CustomerTypeIdColumn = 3 + StartColumn;
                int ParentIdColumn       = 4 + StartColumn;
                int PathColumn           = 5 + StartColumn;
                int LevelColumn          = 6 + StartColumn;
                int StatusIdColumn       = 7 + StartColumn;
                int DescriptionColumn    = 8 + StartColumn;

                for (int i = StartRow; i <= worksheet.Dimension.End.Row; i++)
                {
                    if (string.IsNullOrEmpty(worksheet.Cells[i + StartRow, StartColumn].Value?.ToString()))
                    {
                        break;
                    }
                    string IdValue             = worksheet.Cells[i + StartRow, IdColumn].Value?.ToString();
                    string CodeValue           = worksheet.Cells[i + StartRow, CodeColumn].Value?.ToString();
                    string NameValue           = worksheet.Cells[i + StartRow, NameColumn].Value?.ToString();
                    string CustomerTypeIdValue = worksheet.Cells[i + StartRow, CustomerTypeIdColumn].Value?.ToString();
                    string ParentIdValue       = worksheet.Cells[i + StartRow, ParentIdColumn].Value?.ToString();
                    string PathValue           = worksheet.Cells[i + StartRow, PathColumn].Value?.ToString();
                    string LevelValue          = worksheet.Cells[i + StartRow, LevelColumn].Value?.ToString();
                    string StatusIdValue       = worksheet.Cells[i + StartRow, StatusIdColumn].Value?.ToString();
                    string DescriptionValue    = worksheet.Cells[i + StartRow, DescriptionColumn].Value?.ToString();

                    CustomerGrouping CustomerGrouping = new CustomerGrouping();
                    CustomerGrouping.Code        = CodeValue;
                    CustomerGrouping.Name        = NameValue;
                    CustomerGrouping.Path        = PathValue;
                    CustomerGrouping.Level       = long.TryParse(LevelValue, out long Level) ? Level : 0;
                    CustomerGrouping.Description = DescriptionValue;
                    CustomerType CustomerType = CustomerTypes.Where(x => x.Id.ToString() == CustomerTypeIdValue).FirstOrDefault();
                    CustomerGrouping.CustomerTypeId = CustomerType == null ? 0 : CustomerType.Id;
                    CustomerGrouping.CustomerType   = CustomerType;
                    Status Status = Statuses.Where(x => x.Id.ToString() == StatusIdValue).FirstOrDefault();
                    CustomerGrouping.StatusId = Status == null ? 0 : Status.Id;
                    CustomerGrouping.Status   = Status;

                    CustomerGroupings.Add(CustomerGrouping);
                }
            }
            CustomerGroupings = await CustomerGroupingService.Import(CustomerGroupings);

            if (CustomerGroupings.All(x => x.IsValidated))
            {
                return(Ok(true));
            }
            else
            {
                List <string> Errors = new List <string>();
                for (int i = 0; i < CustomerGroupings.Count; i++)
                {
                    CustomerGrouping CustomerGrouping = CustomerGroupings[i];
                    if (!CustomerGrouping.IsValidated)
                    {
                        string Error = $"Dòng {i + 2} có lỗi:";
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Id)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Id)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Code)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Code)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Name)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Name)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.CustomerTypeId)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.CustomerTypeId)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.ParentId)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.ParentId)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Path)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Path)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Level)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Level)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.StatusId)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.StatusId)];
                        }
                        if (CustomerGrouping.Errors.ContainsKey(nameof(CustomerGrouping.Description)))
                        {
                            Error += CustomerGrouping.Errors[nameof(CustomerGrouping.Description)];
                        }
                        Errors.Add(Error);
                    }
                }
                return(BadRequest(Errors));
            }
        }
Exemplo n.º 11
0
        private IQueryable <CustomerTypeDAO> DynamicOrder(IQueryable <CustomerTypeDAO> query, CustomerTypeFilter filter)
        {
            switch (filter.OrderType)
            {
            case OrderType.ASC:
                switch (filter.OrderBy)
                {
                case CustomerTypeOrder.Id:
                    query = query.OrderBy(q => q.Id);
                    break;

                case CustomerTypeOrder.Code:
                    query = query.OrderBy(q => q.Code);
                    break;

                case CustomerTypeOrder.Name:
                    query = query.OrderBy(q => q.Name);
                    break;
                }
                break;

            case OrderType.DESC:
                switch (filter.OrderBy)
                {
                case CustomerTypeOrder.Id:
                    query = query.OrderByDescending(q => q.Id);
                    break;

                case CustomerTypeOrder.Code:
                    query = query.OrderByDescending(q => q.Code);
                    break;

                case CustomerTypeOrder.Name:
                    query = query.OrderByDescending(q => q.Name);
                    break;
                }
                break;
            }
            query = query.Skip(filter.Skip).Take(filter.Take);
            return(query);
        }
Exemplo n.º 12
0
        private IQueryable <CustomerTypeDAO> OrFilter(IQueryable <CustomerTypeDAO> query, CustomerTypeFilter filter)
        {
            if (filter.OrFilter == null || filter.OrFilter.Count == 0)
            {
                return(query);
            }
            IQueryable <CustomerTypeDAO> initQuery = query.Where(q => false);

            foreach (CustomerTypeFilter CustomerTypeFilter in filter.OrFilter)
            {
                IQueryable <CustomerTypeDAO> queryable = query;
                if (CustomerTypeFilter.Id != null && CustomerTypeFilter.Id.HasValue)
                {
                    queryable = queryable.Where(q => q.Id, CustomerTypeFilter.Id);
                }
                if (CustomerTypeFilter.Code != null && CustomerTypeFilter.Code.HasValue)
                {
                    queryable = queryable.Where(q => q.Code, CustomerTypeFilter.Code);
                }
                if (CustomerTypeFilter.Name != null && CustomerTypeFilter.Name.HasValue)
                {
                    queryable = queryable.Where(q => q.Name, CustomerTypeFilter.Name);
                }
                initQuery = initQuery.Union(queryable);
            }
            return(initQuery);
        }
Exemplo n.º 13
0
 private IQueryable <CustomerTypeDAO> DynamicFilter(IQueryable <CustomerTypeDAO> query, CustomerTypeFilter filter)
 {
     if (filter == null)
     {
         return(query.Where(q => false));
     }
     if (filter.Id != null && filter.Id.HasValue)
     {
         query = query.Where(q => q.Id, filter.Id);
     }
     if (filter.Code != null && filter.Code.HasValue)
     {
         query = query.Where(q => q.Code, filter.Code);
     }
     if (filter.Name != null && filter.Name.HasValue)
     {
         query = query.Where(q => q.Name, filter.Name);
     }
     query = OrFilter(query, filter);
     return(query);
 }
Exemplo n.º 14
0
        private async Task <List <CustomerType> > DynamicSelect(IQueryable <CustomerTypeDAO> query, CustomerTypeFilter filter)
        {
            List <CustomerType> CustomerTypes = await query.Select(q => new CustomerType()
            {
                Id   = filter.Selects.Contains(CustomerTypeSelect.Id) ? q.Id : default(long),
                Code = filter.Selects.Contains(CustomerTypeSelect.Code) ? q.Code : default(string),
                Name = filter.Selects.Contains(CustomerTypeSelect.Name) ? q.Name : default(string),
            }).ToListAsync();

            return(CustomerTypes);
        }