public ActionResult Index(int KPILogDetailId, List <KPILogDetail_ItemViewModel> model, int KPICatalogId) { double totalScores = 0; foreach (var item in model) { KPILogDetail_Item KPILogDetail_Item = KPILogDetail_ItemRepository.GetKPILogDetail_ItemById(item.Id); KPILogDetail_Item.ModifiedDate = DateTime.Now; KPILogDetail_Item.ModifiedUserId = WebSecurity.CurrentUserId; KPILogDetail_Item.AchieveScore = item.AchieveScore; if (KPILogDetail_Item.TargetScore_To > KPILogDetail_Item.TargetScore_From) { KPILogDetail_Item.AchieveKPIWeight = KPILogDetail_Item.AchieveScore / KPILogDetail_Item.TargetScore_To * KPILogDetail_Item.KPIWeight; } else { KPILogDetail_Item.AchieveKPIWeight = (1 - KPILogDetail_Item.AchieveScore / KPILogDetail_Item.TargetScore_From) * KPILogDetail_Item.KPIWeight; } KPILogDetail_ItemRepository.UpdateKPILogDetail_Item(KPILogDetail_Item); totalScores += KPILogDetail_Item.AchieveKPIWeight; } KPILogDetail KPILogDetail = KPILogDetailRepository.GetAllKPILogDetail() .Where(item => item.Id == KPILogDetailId) .FirstOrDefault(); if (KPILogDetail != null) { var KPICatalog = KPICatalogRepository.GetKPICatalogById(KPICatalogId); if (totalScores >= KPICatalog.ExpectScore) { KPILogDetail.Completed = true; } else { KPILogDetail.Completed = false; } KPILogDetail.AchieveKPIWeight = totalScores; KPILogDetailRepository.UpdateKPILogDetail(KPILogDetail); } return(RedirectToAction("Index", new { KPILogDetailId = KPILogDetailId, KPICatalogId = KPICatalogId })); }
public ActionResult Create(int KPILogId, int StaffId, int KPICatalogId) { KPILogDetail KPILogDetail = KPILogDetailRepository.GetAllKPILogDetail() .Where(item => item.KPILogId == KPILogId && item.StaffId == StaffId) .FirstOrDefault(); if (KPILogDetail == null) { KPILogDetail = new KPILogDetail(); KPILogDetail.IsDeleted = false; KPILogDetail.CreatedUserId = WebSecurity.CurrentUserId; KPILogDetail.ModifiedUserId = WebSecurity.CurrentUserId; KPILogDetail.CreatedDate = DateTime.Now; KPILogDetail.ModifiedDate = DateTime.Now; KPILogDetail.KPILogId = KPILogId; KPILogDetail.StaffId = StaffId; KPILogDetailRepository.InsertKPILogDetail(KPILogDetail); var listKPIItem = KPIItemRepository.GetAllKPIItem() .Where(item => item.KPICatalogId == KPICatalogId) .ToList(); //Thêm tiêu chí foreach (var item in listKPIItem) { var KPILogDetail_Item = new KPILogDetail_Item(); AutoMapper.Mapper.Map(item, KPILogDetail_Item); KPILogDetail_Item.IsDeleted = false; KPILogDetail_Item.CreatedUserId = WebSecurity.CurrentUserId; KPILogDetail_Item.ModifiedUserId = WebSecurity.CurrentUserId; KPILogDetail_Item.CreatedDate = DateTime.Now; KPILogDetail_Item.ModifiedDate = DateTime.Now; KPILogDetail_Item.KPILogDetailId = KPILogDetail.Id; KPILogDetail_ItemRepository.InsertKPILogDetail_Item(KPILogDetail_Item); } } return(Content("success")); }