public IActionResult Get()
        {
            List <LeadReportViewModel> leadReports = new List <LeadReportViewModel>();
            IEnumerable <Lead>         leadNames   = _leadRepository.GetAll();



            foreach (Lead val in leadNames)
            {
                LeadReportViewModel leadReport = new LeadReportViewModel();

                //total Revenue
                leadReport.TotalRevenue = _workDescriptionRepository.AllIncluding(c => c.Job.Customer, j => j.Job, c => c.Job.Customer.LeadType)
                                          .Where(c => c.Job.Customer.LeadType.Name == val.Name.ToString())
                                          .Sum(c => c.Revenue);
                //
                leadReport.Lead = val.Name.ToString();
                //
                leadReport.NetProfit = leadReport.TotalRevenue - val.WeeklyCost;
                //
                leadReport.CallsReceived = _customerRepository.AllIncluding(s => s.LeadType).Where(c => c.LeadType.Name == val.Name).Count();
                //
                leadReport.TotalAppt = _jobRepository.AllIncluding(s => s.Customer.LeadType)
                                       .Where(c => c.Customer.LeadType.Name == val.Name).Count();
                //
                try
                {
                    leadReport.BookedPercent = Math.Round((leadReport.TotalAppt / leadReport.CallsReceived) * 100, 2);
                }
                catch (DivideByZeroException)
                { leadReport.BookedPercent = 0; }
                //
                try
                {
                    leadReport.CostCall = val.WeeklyCost / leadReport.CallsReceived;
                }
                catch (DivideByZeroException) {
                    leadReport.CostCall = 0;
                }
                //
                try
                {
                    leadReport.CostLead = val.WeeklyCost / leadReport.TotalAppt;
                }
                catch (DivideByZeroException)
                {
                    leadReport.CostLead = 0;
                }

                leadReport.LeadCost = val.WeeklyCost;

                leadReports.Add(leadReport);
            }

            return(new OkObjectResult(leadReports));
        }
Beispiel #2
0
        public IActionResult Get()
        {
            var pagination = Request.Headers["Pagination"];

            if (!string.IsNullOrEmpty(pagination))
            {
                string[] vals = pagination.ToString().Split(',');
                int.TryParse(vals[0], out page);
                int.TryParse(vals[1], out pageSize);
            }

            int currentPage     = page;
            int currentPageSize = pageSize;
            var totalLeads      = _leadRepository.Count();
            var totalPages      = (int)Math.Ceiling((double)totalLeads / pageSize);


            IEnumerable <Lead> _leads = _leadRepository
                                        .GetAll()
                                        .OrderBy(u => u.Name)
                                        .Skip((currentPage - 1) * currentPageSize)
                                        .Take(currentPageSize)
                                        .ToList();

            IEnumerable <LeadViewModel> _leadsVM = Mapper.Map <IEnumerable <Lead>, IEnumerable <LeadViewModel> >(_leads);

            Response.AddPagination(page, pageSize, totalLeads, totalPages);

            return(new OkObjectResult(_leadsVM));
        }
Beispiel #3
0
 public IEnumerable <Lead> GetAllLeads()
 {
     try
     {
         IEnumerable <Lead> list = _leadRepository.GetAll();
         return(list);
     }
     catch
     {
         //обрабатываем ошибку, записываем в логи
         return(null);
     }
 }
 public IQueryable <LeadType> GetLeadTypes()
 {
     return(_leadRepository.GetAll());
 }