public ActionResult DseProfile(int id) { Session["BreadcrumbList"] = Utils.HtmlExtensions.SetBreadcrumbs((List<BreadcrumbModel>)Session["BreadcrumbList"], string.Format("/Dealer/DseProfile?id={0}", id), "Profile"); var trainings = trainingProfileMapService.FindTrainingProfileMaps(x => x.DealerManpowerId == id).GroupBy( x => x.Training); var manpower = manpowerService.GetDealerManpower(id); var targets = targetService.FindTargets(dealerManPowerId: id); var monthsIds = targets.Select(x => x.MonthId).Distinct(); var variantsIds = targets.Select(x => x.ProductVarientId).Distinct(); var months = monthsIds.Select(x => dealerManpowerService.FindMonthById(x)); var variants = variantsIds.Select(x => dealerManpowerService.FindProductById(x)).OrderBy(x => x.Name); List<Target> pMtargets = new List<Target>(); foreach (var productVarient in variantsIds) { var varientTargets = targets.Where(x => x.ProductVarientId == productVarient); foreach (var month in monthsIds) { var monthlyTarget = varientTargets.Single(x => x.MonthId == month && x.ProductVarientId == productVarient); var target = new Target(); target.Actual = monthlyTarget.Actual; target.T1 = monthlyTarget.Target1; target.T2 = monthlyTarget.Target2; target.Month = months.Single(x => x.Id == month).Name; target.ProductVariant = variants.Single(x => x.Id == productVarient).Name; pMtargets.Add(target); } } var model = new ProfileViewModel { Manpower = DealerManpowerModel.FromDomainModel(manpower), Trainings = (from training in trainings let maxDate = training.Max(x => x.LastTrainingDate) let date = DateTime.Now - maxDate select new TrainingProfileModel { Id = 0, TrainingId = training.Key.Id, Training = training.Key.Name, TrainingDate = maxDate, NumberOfTrainings = training.Count(), NumberOfDays = date.HasValue ? date.Value.Days : 0 }).ToList(), Months = months.Select(x => x.Name), Varients = variants.Select(x => x.Name), ProductMonthsTagets = pMtargets }; model.Manpower.Productivity = manpower.Targets.Any() ? Math.Round(manpower.Targets.Average(x => x.Actual), 2) : 0; ViewBag.List = Session["BreadcrumbList"]; return View("Profile", model); }
public ActionResult DseProfile(int id) { Session["BreadcrumbList"] = Utils.HtmlExtensions.SetBreadcrumbs((List<BreadcrumbModel>)Session["BreadcrumbList"], string.Format("/Dealer/DseProfile?id={0}", id), "Profile"); var trainings = trainingProfileMapService.FindTrainingProfileMaps(x => x.DealerManpowerId == id).GroupBy( x => x.Training); var manpower = manpowerService.GetDealerManpower(id); var year = DateTime.Now.Year; var targets = targetService.FindTargets(dealerManPowerId: id); var monthsIds = targets.Select(x => x.MonthId).Distinct(); var variantsIds = targets.Select(x => x.ProductVarientId).Distinct(); var months = monthsIds.Select(x => dealerManpowerService.FindMonths(monthId: x, year: year)); var variants = variantsIds.Select(x => dealerManpowerService.FindProductById(x)).OrderBy(x => x.Name); var modelMonths = new List<string>(); List<Target> pMtargets = new List<Target>(); int j = 0; foreach (var productVarient in variantsIds) { j++; var varientTargets = targets.Where(x => x.ProductVarientId == productVarient); for (int i = 0; i < 12; i++) { Month month = null; if (i == 0) { month = months.SingleOrDefault(x => x.Name == "January") ?? new Month { Name = "January" }; } else if (i == 1) { month = months.SingleOrDefault(x => x.Name == "February") ?? new Month { Name = "February" }; } else if (i == 2) { month = months.SingleOrDefault(x => x.Name == "March") ?? new Month { Name = "March" }; } else if (i == 3) { month = months.SingleOrDefault(x => x.Name == "April") ?? new Month { Name = "April" }; } else if (i == 4) { month = months.SingleOrDefault(x => x.Name == "May") ?? new Month { Name = "May" }; } else if (i == 5) { month = months.SingleOrDefault(x => x.Name == "June") ?? new Month { Name = "June" }; } else if (i == 6) { month = months.SingleOrDefault(x => x.Name == "July") ?? new Month { Name = "July" }; } else if (i == 7) { month = months.SingleOrDefault(x => x.Name == "August") ?? new Month { Name = "August" }; } else if (i == 8) { month = months.SingleOrDefault(x => x.Name == "Sepetember") ?? new Month { Name = "September" }; } else if (i == 9) { month = months.SingleOrDefault(x => x.Name == "October") ?? new Month { Name = "October" }; } else if (i == 10) { month = months.SingleOrDefault(x => x.Name == "November") ?? new Month { Name = "November" }; } else if (i == 11) { month = months.SingleOrDefault(x => x.Name == "December") ?? new Month { Name = "December" }; } if (month.Id != 0 && j == 1) { modelMonths.Add(month.Name); } var monthlyTarget = varientTargets.SingleOrDefault(x => x.MonthId == month.Id && x.ProductVarientId == productVarient); var target = new Target(); if (monthlyTarget != null) { target.Actual = monthlyTarget.Actual; target.T1 = monthlyTarget.Target1; target.T2 = monthlyTarget.Target2; target.Month = month.Name; target.ProductVariant = variants.Single(x => x.Id == productVarient).Name; pMtargets.Add(target); } } } var model = new ProfileViewModel { Manpower = DealerManpowerModel.FromDomainModel(manpower), Trainings = (from training in trainings let maxDate = training.Max(x => x.LastTrainingDate) let date = DateTime.Now - maxDate select new TrainingProfileModel { Id = 0, TrainingId = training.Key.Id, Training = training.Key.Name, TrainingDate = maxDate, NumberOfTrainings = training.Count(), NumberOfDays = date.HasValue ? date.Value.Days : 0, }).ToList(), Months = modelMonths.Select(x => x), Varients = variants.Select(x => x.Name), ProductMonthsTagets = pMtargets, Dseid = id }; model.Manpower.Productivity = manpower.Targets.Any() ? Math.Round(manpower.Targets.Average(x => x.Actual), 2) : 0; ViewBag.List = Session["BreadcrumbList"]; return View("Profile", model); }