Exemplo n.º 1
0
        public ActionResult DsmMapping(DsmDseMapViewModel model)
        {
            var currentDate = DateTime.Now;
            var currentMonth = masterService.FindAndCreateMonth(currentDate.ToString("MMMM"), currentDate.Year);
            var targets = targetService.FindTargets(x => x.MonthId == currentMonth.Id && model.DseIds.Contains(x.Id));
            if (model.DseIds == null) {
                model.DseIds = new List<int>();
            }

            var user = userService.GetUserByUserName(User.Identity.Name);
            var dsmDseTargetMaps = model.DseIds.Select(x => new DsmDseTargetMap { MonthId = currentMonth.Id, DseId = x, DsmId = model.DsmId, UserId = user.Id });
            dsmDseTargetMapService.UpdateDsmDseTargetMap(dsmDseTargetMaps, dsmId: model.DsmId, userId: user.Id, monthId: currentMonth.Id);
            targetService.UpdateDsmTarget(model.DsmId, user.Id, currentMonth.Id);

            if (targets.Any()) {
                var tempdata = targets.GroupBy(x => x.ProductVarientId);
                foreach (var target in tempdata) {
                    var dsm =
                        targetService.FindTargets(
                            x =>
                            x.MonthId == currentMonth.Id && x.DealerManpowerId == model.DsmId && x.ProductVarientId == target.Key);
                    var dsmTarget = dsm.Any() ? dsm.First() : new Repository.Target();
                    dsmTarget.Actual = target.Sum(x => x.Actual);
                    dsmTarget.Target1 = target.Sum(x => x.Target1);
                    dsmTarget.Target2 = target.Sum(x => x.Target2);
                    dsmTarget.ProductVarientId = target.Key;
                    dsmTarget.MonthId = currentMonth.Id;
                    dsmTarget.DealerManpowerId = model.DsmId;
                    if (dsmTarget.Id > 0) {
                        targetService.UpdateTarget(dsmTarget);
                    } else {
                        targetService.AddTarget(new[] { dsmTarget });
                    }
                }
            }
            return Json(new { success = true }, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 2
0
 public ActionResult DsmMapping(DsmDseMapViewModel model)
 {
     var currentDate = DateTime.Now;
     var currentMonth = _masterService.FindAndCreateMonth(currentDate.ToString("MMMM"), currentDate.Year);
     if (model.DseIds == null)
     {
         model.DseIds = new List<int>();
     }
     var user = userService.GetUserByUserName(User.Identity.Name);
     var dsmDseTargetMaps = model.DseIds.Select(x => new DsmDseTargetMap { MonthId = currentMonth.Id, DseId = x, DsmId = model.DsmId, UserId = user.Id });
     dsmDseTargetMapService.UpdateDsmDseTargetMap(dsmDseTargetMaps, dsmId: model.DsmId, userId: user.Id, monthId: currentMonth.Id);
     targetService.UpdateDsmTarget(model.DsmId, user.Id, currentMonth.Id);
     return Json(new { success = true }, JsonRequestBehavior.AllowGet);
 }