Exemplo n.º 1
0
 //kiểm tra có phải là người cuối cùng đánh giá ko?
 public bool CheckOrderEnd(Eva_PerformanceEva obj)
 {
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repoPE     = new Eva_PerformanceEvaRepository(unitOfWork);
         var objMax     = repoPE.FindBy(x => x.PerformanceID == obj.PerformanceID).Where(x => x.IsDelete == null).Max(x => x.OrderEva);
         if (objMax == obj.OrderEva)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 2
0
        public Eva_PerformanceEvaEntity EditPerformanceEva(Eva_PerformanceEvaEntity model)
        {
            var         Performance    = new Eva_Performance();
            var         PerformanceEva = new Eva_PerformanceEva();
            List <Guid> ilID           = model.PerformanceEvaDetails.Select(x => x.ID).ToList();



            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoP      = new Eva_PerformanceRepository(unitOfWork);
                var repoPE     = new Eva_PerformanceEvaRepository(unitOfWork);
                var repoPED    = new Eva_PerformanceEvaDetailRepository(unitOfWork);
                PerformanceEva = repoPE.GetById(model.ID);
                //cập nhật đánh giá của người đánh giá Eva_PerformanceEva
                if (PerformanceEva != null)
                {
                    //PerformanceEva.AttachFile = model.AttachFile.Substring(0, model.AttachFile.LastIndexOf("_"));
                    PerformanceEva.AttachFile = model.AttachFile;
                    if (CheckOrderEnd(PerformanceEva) == true)
                    {
                        PerformanceEva.Status = PerformaceEvaStatus.E_APPROVE_END.ToString();
                    }
                    else
                    {
                        PerformanceEva.Status = "E_APPROVE_" + PerformanceEva.OrderEva.ToString();
                    }
                    PerformanceEva.Strengths  = model.Strengths;
                    PerformanceEva.Weaknesses = model.Weaknesses;
                    PerformanceEva.LevelID    = model.LevelID;
                    PerformanceEva.ResultNote = model.ResultNote;
                    PerformanceEva.Proportion = model.Proportion;
                    PerformanceEva.TotalMark  = model.TotalMark;
                }
                repoPE.SaveChanges();
                //Cập nhật ngược status và Level, Strengths, Weakness, Resultnote cho Eva_Performance theo status Eva_PerformanceEva
                Performance = repoP.GetById(PerformanceEva.PerformanceID ?? Guid.Empty);
                if (Performance != null)
                {
                    Performance.Status = PerformanceEva.Status;
                    if (PerformanceEva.LevelID.HasValue)
                    {
                        Performance.LevelID = PerformanceEva.LevelID;
                    }
                    if (!string.IsNullOrEmpty(PerformanceEva.Strengths))
                    {
                        Performance.Strengths = PerformanceEva.Strengths;
                    }
                    if (!string.IsNullOrEmpty(PerformanceEva.Weaknesses))
                    {
                        Performance.Weaknesses = PerformanceEva.Weaknesses;
                    }
                    if (!string.IsNullOrEmpty(PerformanceEva.ResultNote))
                    {
                        Performance.ResultNote = PerformanceEva.ResultNote;
                    }
                    repoP.SaveChanges();
                }
                //cập nhật average cho Eva_Performance khi có người đánh giá

                var    ilPerformanceEva = repoPE.FindBy(x => x.IsDelete == null && x.OrderEva <= PerformanceEva.OrderEva && x.OrderEva > 0 && x.TotalMark.HasValue).ToList();
                double?totalmark        = ilPerformanceEva.Sum(x => x.TotalMark) / ilPerformanceEva.Count();

                float _totalMark = 0;
                float.TryParse(Math.Round(totalmark ?? 0, 2).ToString(), out _totalMark);
                Performance.TotalMark = _totalMark;  //float.Parse(Math.Round(totalmark??0,2).ToString());
                repoP.SaveChanges();



                //cập nhật chi tiết người đánh giá Eva_PerformanceEvaDetail


                Eva_PerformanceEvaDetail        objPerformanceEvaDetail = null;
                List <Eva_PerformanceEvaDetail> ilPerformanceEvaDetail  = repoPED.FindBy(x => ilID.Contains(x.ID)).ToList();
                var ilobj = model.PerformanceEvaDetails.ToList();
                foreach (var obj in ilobj)
                {
                    objPerformanceEvaDetail            = repoPED.GetById(obj.ID);
                    objPerformanceEvaDetail.KPIName    = obj.KPIName;
                    objPerformanceEvaDetail.Evaluation = obj.Evaluation;
                    if (obj.Mark.HasValue)
                    {
                        objPerformanceEvaDetail.Mark = obj.Mark;
                    }
                }
                repoPED.SaveChanges();
            }

            return(model);
        }