Пример #1
0
        public BaseResponse BatchUpdateKpiAchievements(BatchUpdateKpiAchievementRequest request)
        {
            var response = new BaseResponse();
            try
            {
                int i = 0;
                foreach (var item in request.BatchUpdateKpiAchievementItemRequest)
                {
                    var kpiAchievement = item.MapTo<KpiAchievement>();
                    var exist = DataContext.KpiAchievements.FirstOrDefault(x => x.Kpi.Id == item.KpiId && x.PeriodeType == item.PeriodeType && x.Periode == item.Periode && x.Value == item.Value && x.Remark == item.Remark);
                    //skip no change value
                    if (exist != null)
                    {
                        continue;
                    }
                    var attachedEntity = DataContext.KpiAchievements.FirstOrDefault(x => x.Kpi.Id == item.KpiId && x.PeriodeType == item.PeriodeType && x.Periode == item.Periode);
                    if (attachedEntity != null)
                    {
                        kpiAchievement.Id = attachedEntity.Id;
                    }
                    //jika tidak ada perubahan di skip aja
                    //if (existing.Value.Equals(item.Value) && existing.Periode.Equals(item.Periode) && existing.Kpi.Id.Equals(item.KpiId) && existing.PeriodeType.Equals(item.PeriodeType)) {
                    //    break;
                    //}
                    if (kpiAchievement.Id != 0)
                    {
                        //var attachedEntity = DataContext.KpiAchievements.Find(item.Id);
                        if (attachedEntity != null && DataContext.Entry(attachedEntity).State != EntityState.Detached)
                        {
                            DataContext.Entry(attachedEntity).State = EntityState.Detached;
                        }
                        DataContext.KpiAchievements.Attach(kpiAchievement);
                        DataContext.Entry(kpiAchievement).State = EntityState.Modified;
                    }
                    else
                    {
                        kpiAchievement.Kpi = DataContext.Kpis.FirstOrDefault(x => x.Id == item.KpiId);
                        DataContext.KpiAchievements.Add(kpiAchievement);
                    }
                    i++;
                }
                DataContext.SaveChanges();
                response.IsSuccess = true;
                if (i > 0)
                {
                    response.Message = string.Format("{0}  KPI Achievement items has been updated successfully", i.ToString());
                }
                else
                {
                    response.Message = "File Successfully Parsed, but no data changed!";
                }

            }
            catch (InvalidOperationException invalidOperationException)
            {
                response.Message = invalidOperationException.Message;
            }
            catch (ArgumentNullException argumentNullException)
            {
                response.Message = argumentNullException.Message;
            }
            return response;
        }
Пример #2
0
 private BaseResponse UpdateKpiAchievement(IEnumerable<ConfigurationViewModel.Item> data)
 {
     var response = new BaseResponse { IsSuccess = false, Message = "Data Not Valid" };
     if (data != null)
     {
         var batch = new BatchUpdateKpiAchievementRequest();
         foreach (var datum in data)
         {
             var prepare = new UpdateKpiAchievementItemRequest() { Id = datum.Id, KpiId = datum.KpiId, Periode = datum.Periode, Value = datum.Value, PeriodeType = datum.PeriodeType, Remark = datum.Remark };// data.MapTo<UpdateKpiAchievementItemRequest>();
             batch.BatchUpdateKpiAchievementItemRequest.Add(prepare);
         }
         response = _kpiAchievementService.BatchUpdateKpiAchievements(batch);
     }
     return response;
 }
Пример #3
0
 private BaseResponse _UpdateKpiAchievement(List<ConfigurationViewModel.Item> datas, string periodeType, int year, int month)
 {
     var response = new BaseResponse();
     if (datas != null)
     {
         var batch = new BatchUpdateKpiAchievementRequest();
         foreach (var data in datas)
         {
             var prepare = new UpdateKpiAchievementItemRequest() { Id = data.Id, KpiId = data.KpiId, Periode = data.Periode, Value = data.Value, PeriodeType = data.PeriodeType, Remark = data.Remark };// data.MapTo<UpdateKpiAchievementItemRequest>();
             batch.BatchUpdateKpiAchievementItemRequest.Add(prepare);
         }
         response = _kpiAchievementService.BatchUpdateKpiAchievements(batch);
     }
     return response;
 }