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; }
public Eva_PerformanceEntity AddPerfomance360(Eva_PerformanceEntity model, bool isSelft) { /* * Goal(Luu đánh giá nhân viên) * Steps : * Step1 : Insert Eva_Performance * Step2 : Tự động insert xuống table Eva_PerformanceForDetail * Step3 : Tự động insert xuống table Eva_PerformanceEva &Eva_PerformanceEvaDetail * - Tự Đánh Giá : orderNo =0 (Ngoai ra orderNo >0) */ var evaluationStatus = PerformaceEvaStatus.E_WAITING.ToString(); var result = new Eva_PerformanceEntity(); var performanceForDetail = new Eva_PerformanceForDetail(); var performanceEva = new Eva_PerformanceEva(); var performanceEvaDetail = new Eva_PerformanceEvaDetail(); using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoPerformance = new Eva_PerformanceRepository(unitOfWork); var repoEvaluator = new Eva_EvaluatorRepository(unitOfWork); var repoPerformanceForDetail = new Eva_PerformanceForDetailRepository(unitOfWork); var repoPerformanceEva = new Eva_PerformanceEvaRepository(unitOfWork); var repoPerformanceEvaDetail = new Eva_PerformanceEvaDetailRepository(unitOfWork); #region step1 : thêm Eva_Performance result = model; if (result != null && result.ID == Guid.Empty) { result.Status = evaluationStatus; } Add(result); #endregion #region Step2 : Tự động insert xuống table Eva_PerformanceForDetail dựa vào các KPI tương ứng //lay ds KPIs (kèm theo Marks và Evaluation) - lay dữ liệu từ edit trên lưới var kpis = model.KPIs;//cac tieu chi danh gia var kpiByTempalateIds = kpis; var lstPerformanceForDetails = new List<Eva_PerformanceForDetail>(); foreach (var kpiByTempalateId in kpiByTempalateIds) { performanceForDetail = new Eva_PerformanceForDetail(); performanceForDetail.ID = Guid.NewGuid(); if (result != null) { performanceForDetail.PerformanceID = result.ID; } performanceForDetail.KPIID = kpiByTempalateId.ID; performanceForDetail.KPIName = kpiByTempalateId.KPIName; performanceForDetail.OrderKPI = kpiByTempalateId.OrderNumber; performanceForDetail.OrderNumber = kpiByTempalateId.OrderNumber; performanceForDetail.Rate = kpiByTempalateId.Rate; lstPerformanceForDetails.Add(performanceForDetail); repoPerformanceForDetail.Add(performanceForDetail);//add vao repo } repoPerformanceForDetail.SaveChanges(); #endregion #region Step3 : Tự động insert xuống table Eva_PerformanceEva &Eva_PerformanceEvaDetail #region Luu bảng Eva_PerformanceEva (cho từng người đánh giá) var lstPerformanceEvaIDs = new List<Guid>(); int orderNo = 1; var performanceEvaSeftId = Guid.Empty;//ID cua bang Eva_PerformanceEva #region Tự đánh giá : tự động add 1 người đánh giá là chính bảng thân người tạo bảng đánh giá if (isSelft && result != null && model != null && model.ProfileID != Guid.Empty) { //tu tao nguoi danh gia la ban than performanceEva = new Eva_PerformanceEva(); performanceEva.ID = Guid.NewGuid(); performanceEvaSeftId = performanceEva.ID; lstPerformanceEvaIDs.Add(performanceEva.ID); performanceEva.PerformanceID = result.ID; performanceEva.EvaluatorID = model.ProfileID; performanceEva.Status = PerformaceEvaStatus.E_SEFT.ToString();//evaluationStatus; performanceEva.OrderEva = 0; repoPerformanceEva.Add(performanceEva); //cap nhat lai status cua Eva_Performance var performanceEntity = repoPerformance.GetById(result.ID); if (performanceEntity != null) { performanceEntity.Status = PerformaceEvaStatus.E_SEFT.ToString(); repoPerformance.SaveChanges(); } } #endregion //Lấy ds người đánh giá theo NV và loại đánh giá var evaluatorIds = model.EvaluatorIDs; var evaluatorObjs = repoEvaluator.FindBy(p => p.IsDelete == null && evaluatorIds.Contains(p.EvaluatorID ?? Guid.Empty) && p.ProfileID == model.ProfileID && p.PerformanceTypeID == model.PerformanceTypeID).ToList(); evaluatorObjs = evaluatorObjs.OrderBy(p => p.OrderNo).ToList(); foreach (var evaluator in evaluatorObjs) { performanceEva = new Eva_PerformanceEva(); performanceEva.ID = Guid.NewGuid(); lstPerformanceEvaIDs.Add(performanceEva.ID); if (result != null) { performanceEva.PerformanceID = result.ID; } performanceEva.EvaluatorID = evaluator.EvaluatorID; performanceEva.Status = evaluationStatus; performanceEva.OrderEva = orderNo++; repoPerformanceEva.Add(performanceEva); } repoPerformanceEva.SaveChanges(); #endregion #region comment Luu Eva_PerformanceEvaDetail (lưu chi tiết cho bảng đánh giá) //var isSeft = false; ////khởi tạo chi tiet đánh giá cho từng người đánh giá //foreach (var performanceEvaID in lstPerformanceEvaIDs) //{ // //ds cac tieu chí // foreach (var performanceForDetailItem in lstPerformanceForDetails) // { // performanceEvaDetail = new Eva_PerformanceEvaDetail // { // ID = Guid.NewGuid(), // PerfomanceEvaID = performanceEvaID, // PerfomanceDetailID = performanceForDetailItem.ID, // KPIName = performanceForDetailItem.KPIName // }; // #region Dành Cho Tự Đánh Giá // if (performanceEvaSeftId != Guid.Empty && performanceEvaSeftId == performanceEvaID) // { // /*Add Mark va Evaluation cho nguoi danh gia la ban than*/ // //lay kpi theo name tu model de set data cho Mark va Evaluation // var kpi = kpiByTempalateIds.FirstOrDefault(p => p.KPIName == performanceEvaDetail.KPIName); // if (kpi != null) // { // performanceEvaDetail.Mark = kpi.Mark; // performanceEvaDetail.Evaluation = kpi.Evaluation; // } // //đặt flag là tự đánh giá // isSeft = true; // } // repoPerformanceEvaDetail.Add(performanceEvaDetail); // #endregion // } // if (isSeft) // { // performanceEvaSeftId = Guid.Empty; // } //} //repoPerformanceEvaDetail.SaveChanges(); #endregion #endregion } return result; }
//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; }