Example #1
0
        public UpdateOperationDataResponse Update(UpdateOperationDataRequest request)
        {
            var response = new UpdateOperationDataResponse();
            try
            {
                var operationData = request.MapTo<KeyOperationData>();

                if (operationData.Id > 0)
                {
                    operationData = DataContext.KeyOperationDatas.Single(x => x.Id == operationData.Id);
                    request.MapPropertiesToInstance(operationData);
                }
                else
                {
                    DataContext.KeyOperationDatas.Add(operationData);
                }
                operationData.Kpi = DataContext.Kpis.Single(x => x.Id == request.KpiId);
                operationData.Scenario = DataContext.Scenarios.Single(x => x.Id == request.ScenarioId);
                operationData.KeyOperationConfig = DataContext.KeyOperationConfigs.Single(x => x.Id == request.KeyOperationConfigId);
                DataContext.SaveChanges();
                response.Id = operationData.Id;
                response.IsSuccess = true;
                response.Message = "Key Operation Data has been updated successfully";
            }
            catch (InvalidOperationException invalidOperationException)
            {
                response.Message = invalidOperationException.Message;
            }
            catch (ArgumentNullException argumentNullException)
            {
                response.Message = argumentNullException.Message;
            }

            return response;
        }
Example #2
0
 private BaseResponse UpdateOperationData(IEnumerable<ConfigurationViewModel.Item> datas)
 {
     var response = new BaseResponse { IsSuccess = false, Message = "Data Not Valid" };
     if (datas != null)
     {
         var batch = new BatchUpdateOperationDataRequest();
         foreach (var data in datas)
         {
             var prepare = new UpdateOperationDataRequest()
             {
                 Id = data.Id,
                 KpiId = data.KpiId,
                 Periode = data.Periode,
                 Value = data.Value,
                 PeriodeType = data.PeriodeType,
                 Remark = data.Remark,
                 KeyOperationConfigId = data.OperationId,
                 ScenarioId = data.ScenarioId
             };// data.MapTo<UpdateKpiAchievementItemRequest>();
             batch.BatchUpdateOperationDataItemRequest.Add(prepare);
         }
         response = _operationDataService.BatchUpdateOperationDatas(batch);
     }
     return response;
 }
 private BaseResponse _UpdateEconomic(List<OperationDataConfigurationViewModel.Item> datas)
 {
     var response = new BaseResponse();
     if (datas != null)
     {
         var batch = new BatchUpdateOperationDataRequest();
         foreach (var data in datas)
         {
             var prepare = new UpdateOperationDataRequest() { Id = data.Id, KpiId = data.KpiId, Periode = data.Periode, Value = data.Value, PeriodeType = data.PeriodeType, Remark = data.Remark, KeyOperationConfigId = data.OperationId, ScenarioId = data.ScenarioId };// data.MapTo<UpdateKpiAchievementItemRequest>();
             batch.BatchUpdateOperationDataItemRequest.Add(prepare);
         }
         response = _operationDataService.BatchUpdateOperationDatas(batch);
     }
     return response;
 }