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; }
public string ApproveKPIforPerformance(Guid PerformanceID, List<Eva_KPIEntity> list) { string rs = null; using (var context = new VnrHrmDataContext()) { var status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var repoPerformance = new Eva_PerformanceRepository(unitOfWork); var repoPerformanceForDetail = new Eva_PerformanceForDetailRepository(unitOfWork); var repoPerformanceEvaDetail = new Eva_PerformanceEvaDetailRepository(unitOfWork); var repoPerformanceEva = new Eva_PerformanceEvaRepository(unitOfWork); var repoEvaluator = new Eva_EvaluatorRepository(unitOfWork); var lstPerformanceForDetail = repoPerformanceForDetail.FindBy(x => x.PerformanceID == PerformanceID).ToList(); var Performance = repoPerformance.GetById(PerformanceID); if (lstPerformanceForDetail == null && lstPerformanceForDetail.Count == 0) return null; foreach (var item in lstPerformanceForDetail) { var obj = list.FirstOrDefault(x => x.PerformanceForDetailID.HasValue && x.PerformanceForDetailID == item.ID); if (obj != null) { item.DescriptionKP = obj.DescriptionKP; } } repoPerformanceForDetail.SaveChanges(); Performance.Status = "Approve"; repoPerformance.SaveChanges(); rs = Performance.Status; } return rs; }
public bool DeletePerformance(Guid performanceId) { 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); // var evaluatorObjs = repoEvaluator.FindBy(p => evaluators.Contains(p.EvaluatorID ?? Guid.Empty) && p.ProfileID == model.ProfileID && p.PerformanceTypeID == model.PerformanceTypeID).ToList(); //get performance var performanceDelete = repoPerformance.FindBy(p => p.ID == performanceId).FirstOrDefault(); if (performanceDelete != null) { performanceDelete.IsDelete = true; repoPerformance.SaveChanges(); #region xoa performanceForDetail var performanceForDetailDelete = repoPerformanceForDetail.FindBy(p => p.PerformanceID == performanceDelete.ID).ToList(); foreach (var performanceForDetail in performanceForDetailDelete) { performanceForDetail.IsDelete = true; } if (performanceForDetailDelete.Any()) { repoPerformanceForDetail.SaveChanges(); } #endregion #region xoa eva_performanceEva var performanceEvaDelete = repoPerformanceEva.FindBy(p => p.PerformanceID == performanceDelete.ID).ToList(); foreach (var evaPerformanceEva in performanceEvaDelete) { evaPerformanceEva.IsDelete = true; } if (performanceEvaDelete.Any()) { repoPerformanceEva.SaveChanges(); } #endregion #region xoa eva_performanceEvaDetail if (performanceEvaDelete.Any()) { foreach (var evaPerformanceEva in performanceEvaDelete) { var performanceEvaDetailDelete = repoPerformanceEvaDetail.FindBy(p => p.PerfomanceEvaID == evaPerformanceEva.ID) .FirstOrDefault(); if (performanceEvaDetailDelete != null) { performanceEvaDetailDelete.IsDelete = true; } } repoPerformanceEvaDetail.SaveChanges(); } #endregion } } return true; }
/// <summary> /// truoc khi vào màn hình chờ đánh giá , sẽ thêm vào bảng eva_performanceEvaDetail nếu bảng này chưa có data ứng với performanceID /// </summary> /// <param name="performanceEvaID"></param> /// <returns></returns> public bool AddPerformanceEvaDetail360(Guid performanceEvaID) { 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); var performanceEvaDetail = new Eva_PerformanceEvaDetail(); #region Lay DS EvaPerformanceEvaDetail //neu co du lieu => khong tao moi var lstPerformanceEvaDetail = unitOfWork.CreateQueryable<Eva_PerformanceEvaDetail>(Guid.Empty, m => m.PerfomanceEvaID == performanceEvaID).ToList(); if (lstPerformanceEvaDetail.Any()) { return false; } #endregion //lay performanceID var performanceEva = unitOfWork.CreateQueryable<Eva_PerformanceEva>(Guid.Empty, m => m.ID == performanceEvaID).FirstOrDefault(); var performanceID = Guid.Empty; if (performanceEva != null && performanceEva.PerformanceID.HasValue) { performanceID = performanceEva.PerformanceID.Value; } else { return false; } #region lay ds eva_performancefordetail theo performanceID var lstPerformanceForDetails = unitOfWork.CreateQueryable<Eva_PerformanceForDetail>(Guid.Empty, m => m.PerformanceID == performanceID).ToList(); #endregion #region comment Luu Eva_PerformanceEvaDetail (lưu chi tiết cho bảng đánh giá) //khởi tạo chi tiet đánh giá cho người đánh giá if (performanceEvaID != Guid.Empty) { //ds cac tieu chí foreach (var performanceForDetailItem in lstPerformanceForDetails) { performanceEvaDetail = new Eva_PerformanceEvaDetail { ID = Guid.NewGuid(), PerfomanceEvaID = performanceEvaID, PerfomanceDetailID = performanceForDetailItem.ID, KPIName = performanceForDetailItem.KPIName }; repoPerformanceEvaDetail.Add(performanceEvaDetail); } } repoPerformanceEvaDetail.SaveChanges(); #endregion } return false; }
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; }