protected TargetViewModel Map(Target target)
 {
     TargetViewModel targetViewModel = new TargetViewModel();
     if (target.CostCentre != null)
     {
         targetViewModel.CostCentreId = _costCentreRepository.GetById(target.CostCentre.Id).Id;
     }
     targetViewModel.Id = target.Id;
     if (target._Status == EntityStatus.Active)
         targetViewModel.isActive =true;
     targetViewModel.Period = _targetPeriodRepository.GetById(target.TargetPeriod.Id).Id;
     targetViewModel.PeriodName = _targetPeriodRepository.GetById(target.TargetPeriod.Id).Name;
     targetViewModel.TargetValue = target.TargetValue;
     targetViewModel.IsQuantityTarget = target.IsQuantityTarget;
     targetViewModel.CostCentreName = _costCentreRepository.GetById(target.CostCentre.Id).Name;
     targetViewModel.CostCentreType = _costCentreRepository.GetById(target.CostCentre.Id).CostCentreType;
     return targetViewModel;
     }
示例#2
0
 public ActionResult CreateTarget(TargetViewModel tvm)
 {
     ViewBag.DistributorList = _targetViewModelBuilder.GetDistributor();
     ViewBag.PeriodList = _targetViewModelBuilder.GetPeriod();
     try
     {
         tvm.Id = Guid.NewGuid();
         _targetViewModelBuilder.Save(tvm);
         _auditLogViewModelBuilder.AddAuditLog(this.User.Identity.Name, "Create", "Target", DateTime.Now);
         TempData["msg"] = "Target Successfully Created";
         return RedirectToAction("ListTargets");
     }
     catch (DomainValidationException dve)
     {
         ValidationSummary.DomainValidationErrors(dve, ModelState);
         return View();
     }
     catch (Exception exx)
     {
         ViewBag.msg = exx.Message;
         ValidationSummary.DomainValidationErrors(exx.Message, ModelState);
         return View();
     }
 }
 public void Save(TargetViewModel trgViewModel)
 {
     Target trg = new Target(trgViewModel.Id,DateTime.Now,DateTime.Now,EntityStatus.Active) 
     {
      TargetPeriod=_targetPeriodRepository.GetById(trgViewModel.Period),
       CostCentre=_costCentreRepository.GetById(trgViewModel.CostCentreId),
       TargetValue=trgViewModel.TargetValue,
       IsQuantityTarget=trgViewModel.IsQuantityTarget
     };
    
     _targeteRepository.Save(trg );
 }