Beispiel #1
0
        public async Task <CustomerLeadFilter> ToFilter(CustomerLeadFilter filter)
        {
            if (filter.OrFilter == null)
            {
                filter.OrFilter = new List <CustomerLeadFilter>();
            }
            if (CurrentContext.Filters == null || CurrentContext.Filters.Count == 0)
            {
                return(filter);
            }
            List <Organization> Organizations = await OrganizationService.List(new OrganizationFilter
            {
                Skip      = 0,
                Take      = int.MaxValue,
                Selects   = OrganizationSelect.ALL,
                OrderBy   = OrganizationOrder.Id,
                OrderType = OrderType.ASC
            });

            foreach (var currentFilter in CurrentContext.Filters)
            {
                CustomerLeadFilter subFilter = new CustomerLeadFilter();
                filter.OrFilter.Add(subFilter);
                List <FilterPermissionDefinition> FilterPermissionDefinitions = currentFilter.Value;
                foreach (FilterPermissionDefinition FilterPermissionDefinition in FilterPermissionDefinitions)
                {
                    if (FilterPermissionDefinition.Name == nameof(subFilter.AppUserId))
                    {
                        subFilter.AppUserId = FilterBuilder.Merge(subFilter.AppUserId, FilterPermissionDefinition.IdFilter);
                    }
                }
            }
            return(filter);
        }
Beispiel #2
0
        public async Task <ActionResult> Export([FromBody] CustomerLeadReport_CustomerLeadReportFilterDTO CustomerLeadReport_CustomerLeadReportFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }


            CustomerLeadFilter CustomerLeadFilter = ConvertFilterDTOToFilterEntity(CustomerLeadReport_CustomerLeadReportFilterDTO);
            //Lấy danh sách CustomerLead
            var CustomerLeads = await CustomerLeadService.List(CustomerLeadFilter);

            List <CustomerLeadReport_CustomerLeadDTO> CustomerLeadDTOs = CustomerLeads.Select(p => new CustomerLeadReport_CustomerLeadDTO(p)).ToList();
            CustomerLeadReport_CustomerLeadReportDTO  CustomerLeadReport_CustomerLeadReportDTO = new CustomerLeadReport_CustomerLeadReportDTO();
            var STT = 1;

            foreach (var item in CustomerLeadDTOs)
            {
                item.STT = STT;
                STT++;
            }
            var      maxDate = CustomerLeadDTOs.Max(p => p.CreatedAt);
            var      minDate = CustomerLeadDTOs.Min(p => p.CreatedAt);
            DateTime Start   = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadTime?.GreaterEqual == null ?
                               minDate :
                               CustomerLeadReport_CustomerLeadReportFilterDTO.LeadTime.GreaterEqual.Value;

            DateTime End = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadTime?.LessEqual == null ?
                           maxDate :
                           CustomerLeadReport_CustomerLeadReportFilterDTO.LeadTime.LessEqual.Value;

            CustomerLeadReport_CustomerLeadReportDTO.CustomerLeads = CustomerLeadDTOs;

            string path = "Templates/CustomerLeadReport.xlsx";

            byte[]       arr    = System.IO.File.ReadAllBytes(path);
            MemoryStream input  = new MemoryStream(arr);
            MemoryStream output = new MemoryStream();
            dynamic      Data   = new ExpandoObject();

            Data.Start         = Start.AddHours(CurrentContext.TimeZone).ToString("dd-MM-yyyy");
            Data.End           = End.AddHours(CurrentContext.TimeZone).ToString("dd-MM-yyyy");
            Data.CustomerLeads = CustomerLeadReport_CustomerLeadReportDTO.CustomerLeads;
            using (var document = StaticParams.DocumentFactory.Open(input, output, "xlsx"))
            {
                document.Process(Data);
            };

            return(File(output.ToArray(), "application/octet-stream", "BaoCaoLead.xlsx"));
        }
Beispiel #3
0
        public async Task <ActionResult <int> > Count([FromBody] CustomerLeadReport_CustomerLeadReportFilterDTO CustomerLeadReport_CustomerLeadReportFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }

            CustomerLeadFilter CustomerLeadFilter = ConvertFilterDTOToFilterEntity(CustomerLeadReport_CustomerLeadReportFilterDTO);

            return(await CustomerLeadService.Count(CustomerLeadFilter));
        }
Beispiel #4
0
        private CustomerLeadFilter ConvertFilterDTOToFilterEntity(CustomerLeadReport_CustomerLeadReportFilterDTO CustomerLeadReport_CustomerLeadReportFilterDTO)
        {
            CustomerLeadFilter CustomerLeadFilter = new CustomerLeadFilter();

            CustomerLeadFilter.Selects   = CustomerLeadSelect.ALL;
            CustomerLeadFilter.Skip      = CustomerLeadReport_CustomerLeadReportFilterDTO.Skip;
            CustomerLeadFilter.Take      = CustomerLeadReport_CustomerLeadReportFilterDTO.Take;
            CustomerLeadFilter.OrderType = CustomerLeadReport_CustomerLeadReportFilterDTO.OrderType;

            CustomerLeadFilter.Name  = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadName;
            CustomerLeadFilter.Phone = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadPhoneNumber;
            CustomerLeadFilter.Email = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadEmail;
            CustomerLeadFilter.CustomerLeadStatusId = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadStatusId;
            CustomerLeadFilter.CustomerLeadSourceId = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadSourceId;
            CustomerLeadFilter.AppUserId            = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadStaffId;
            CustomerLeadFilter.CreatedAt            = CustomerLeadReport_CustomerLeadReportFilterDTO.LeadTime;

            return(CustomerLeadFilter);
        }
Beispiel #5
0
        public async Task <bool> ValidateId(CustomerLead CustomerLead)
        {
            CustomerLeadFilter CustomerLeadFilter = new CustomerLeadFilter
            {
                Skip = 0,
                Take = 10,
                Id   = new IdFilter {
                    Equal = CustomerLead.Id
                },
                Selects = CustomerLeadSelect.Id
            };

            int count = await UOW.CustomerLeadRepository.Count(CustomerLeadFilter);

            if (count == 0)
            {
                CustomerLead.AddError(nameof(CustomerLeadValidator), nameof(CustomerLead.Id), ErrorCode.IdNotExisted);
            }
            return(count == 1);
        }
Beispiel #6
0
        public async Task <ActionResult <CustomerLeadReport_CustomerLeadReportDTO> > List([FromBody] CustomerLeadReport_CustomerLeadReportFilterDTO CustomerLeadReport_CustomerLeadReportFilterDTO)
        {
            if (UnAuthorization)
            {
                return(Forbid());
            }
            if (!ModelState.IsValid)
            {
                throw new BindException(ModelState);
            }
            CustomerLeadFilter CustomerLeadFilter = ConvertFilterDTOToFilterEntity(CustomerLeadReport_CustomerLeadReportFilterDTO);
            //Lấy danh sách CustomerLead
            var CustomerLeads = await CustomerLeadService.List(CustomerLeadFilter);

            List <CustomerLeadReport_CustomerLeadDTO> CustomerLeadDTOs = CustomerLeads.Select(p => new CustomerLeadReport_CustomerLeadDTO(p)).ToList();
            CustomerLeadReport_CustomerLeadReportDTO  CustomerLeadReport_CustomerLeadReportDTO = new CustomerLeadReport_CustomerLeadReportDTO();

            CustomerLeadReport_CustomerLeadReportDTO.CustomerLeads = CustomerLeadDTOs;
            return(CustomerLeadReport_CustomerLeadReportDTO);
        }
Beispiel #7
0
        public async Task <List <CustomerLead> > List(CustomerLeadFilter CustomerLeadFilter)
        {
            try
            {
                List <CustomerLead> CustomerLeads = await UOW.CustomerLeadRepository.List(CustomerLeadFilter);

                return(CustomerLeads);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(CustomerLeadService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }
Beispiel #8
0
        public async Task <int> Count(CustomerLeadFilter CustomerLeadFilter)
        {
            try
            {
                int result = await UOW.CustomerLeadRepository.Count(CustomerLeadFilter);

                return(result);
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    await Logging.CreateSystemLog(ex, nameof(CustomerLeadService));

                    throw new MessageException(ex);
                }
                else
                {
                    await Logging.CreateSystemLog(ex.InnerException, nameof(CustomerLeadService));

                    throw new MessageException(ex.InnerException);
                }
            }
        }