コード例 #1
0
        public bool AddPerformanceDetail(string kpiIDs, Guid performanceTemplateID)
        {
            var isSuccess = false;
            string status = string.Empty;
            if (kpiIDs != null &&  kpiIDs.Any() && performanceTemplateID != Guid.Empty)
            {
                //chức năng thêm và tiêu chí đánh giá
                var listKPI = kpiIDs.Split(',').Select(x => Guid.Parse(x)).ToList();
                using (var context = new VnrHrmDataContext())
                {
                      var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                    if (listKPI.Any())
	                {
		                var performanceDetails = GetAllUseEntity<Eva_PerformanceDetail>(ref status).Where(p=>p.IsDelete == null && p.PerformanceTemplateID == performanceTemplateID);
                        #region Lay so thu tu lon nhat
                        var maxOrderNumberFollowTemplateId = performanceDetails.Max(m => m.OrderNumber);
                        if (maxOrderNumberFollowTemplateId == null)
                        {
                            maxOrderNumberFollowTemplateId = 0;
                        } 
                        #endregion
                        //lay danh sach rate cua KPI
                        var kpiRates = unitOfWork.CreateQueryable<Eva_KPI>(Guid.Empty, m => listKPI.Contains(m.ID)).Select(m => new { m.ID, m.Rate }).ToList();

                        foreach (var kpiID in listKPI)
                        {
                            if (!performanceDetails.Any(p => p.KPIID == kpiID))
                            {
                                //tao moi
                                var kpiRate = kpiRates.Where(m => m.ID == kpiID).Select(m=>m.Rate).FirstOrDefault();
                                maxOrderNumberFollowTemplateId++;
                                var performanceDetail = new Eva_PerformanceDetailEntity()
                                {
                                    KPIID = kpiID,
                                    PerformanceTemplateID = performanceTemplateID,
                                    OrderNumber = maxOrderNumberFollowTemplateId,
                                    Rate =kpiRate
                                };
                                isSuccess = true;
                                Add(performanceDetail);
                            }
                            else
                            {
                                //edit
                            }
                        } 
	                }
                }
            }

            return isSuccess;
        }
コード例 #2
0
 public Eva_PerformanceDetailEntity EditPerformanceDetail(Guid performanceDetailID, double? rate, int? orderNumber)
 {
     string status = string.Empty;
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var performanceDetailEntity = new Eva_PerformanceDetailEntity();
         var performanceDetail = unitOfWork.CreateQueryable<Eva_PerformanceDetail>(Guid.Empty, m => m.ID == performanceDetailID).FirstOrDefault();
         if (performanceDetail != null)
         {
             performanceDetailEntity = performanceDetail.CopyData<Eva_PerformanceDetailEntity>();
             performanceDetailEntity.Rate = rate;
             performanceDetailEntity.OrderNumber = orderNumber;
             Edit(performanceDetailEntity);
         }              
         return performanceDetailEntity;
     }
 }