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)); }
public IActionResult GetJobs(int id) { 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 totalJobs = _jobRepository.Count(); var totalPages = (int)Math.Ceiling((double)totalJobs / pageSize); IEnumerable <Job> _jobs = _jobRepository .AllIncluding(j => j.JobAssignees, j => j.WorkDescriptions, j => j.Address) .Where(j => j.CustomerId == id) .OrderBy(u => u.Id) .Skip((currentPage - 1) * currentPageSize) .Take(currentPageSize) .ToList(); IEnumerable <JobViewModel> _jobsVM = Mapper.Map <IEnumerable <Job>, IEnumerable <JobViewModel> >(_jobs); Response.AddPagination(page, pageSize, totalJobs, totalPages); return(new OkObjectResult(_jobsVM)); }