private BaseResponse SaveKpiInformations(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var kpiInformations = new List<DerKpiInformation>(); foreach (var item in request.KpiInformations) { if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } kpiInformations.Add(new DerKpiInformation { Kpi = kpi, Position = item.Position, IsOriginalData = item.IsOriginalData, ConfigType = item.ConfigType }); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, IsOriginalData = item.IsOriginalData, ConfigType = item.ConfigType }); } } derLayoutItem.KpiInformations = kpiInformations; DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveDafwc(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { if (request.Id > 0) { } else { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; DataContext.DerLayoutItems.Add(derLayoutItem); } DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveHighlight(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var derHiglight = new DerHighlight(); var selectOption = new SelectOption { Id = request.Highlight.SelectOptionId }; DataContext.SelectOptions.Attach(selectOption); derHiglight.SelectOption = selectOption; derLayoutItem.Highlight = derHiglight; DataContext.DerHighlights.Add(derHiglight); DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
public GetDerLayoutResponse GetDerLayout(int id) { var response = new GetDerLayoutResponse(); try { var derLayout = DataContext.DerLayouts .Include(x => x.Items) .Include(x => x.Items.Select(y => y.DerLayout)) //.Include(x => x.Items.Select(y => y.DerLayout.Items)) /*.Include(x => x.Items.Select(y => y.Artifact)) .Include(x => x.Items.Select(y => y.Artifact.Measurement)) .Include(x => x.Items.Select(y => y.Artifact.Series)) .Include(x => x.Items.Select(y => y.Artifact.Series.Select(z => z.Kpi))) .Include(x => x.Items.Select(y => y.Highlight)) .Include(x => x.Items.Select(y => y.Highlight.SelectOption))*/ .Single(x => x.Id == id); /*Include("PmsConfigs.Pillar") .Include("PmsConfigs.ScoreIndicators") .Include("PmsConfigs.PmsConfigDetailsList.Kpi.Measurement") .Include("PmsConfigs.PmsConfigDetailsList.Kpi.KpiAchievements") .Include("PmsConfigs.PmsConfigDetailsList.Kpi.KpiTargets") .Include("PmsConfigs.PmsConfigDetailsList.Kpi.Pillar") .Include("PmsConfigs.PmsConfigDetailsList.ScoreIndicators")*/ response = derLayout.MapTo<GetDerLayoutResponse>(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateHighlight(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = DataContext.DerLayoutItems.Include(x => x.Highlight).Include(x => x.Highlight.SelectOption).Single(x => x.Id == request.Id); var selectOption = new SelectOption { Id = request.Highlight.SelectOptionId }; DataContext.SelectOptions.Attach(selectOption); derLayoutItem.Highlight.SelectOption = selectOption; DataContext.Entry(derLayoutItem).State = EntityState.Modified; DataContext.SaveChanges(); response.IsSuccess = true; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateUser(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = DataContext.DerLayoutItems.Include(x => x.KpiInformations).Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; derLayoutItem.SignedBy = DataContext.Users.Single(x => x.Id == request.SignedBy); DataContext.Entry(derLayoutItem).State = EntityState.Modified; DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse UpdateKpiInformations(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = DataContext.DerLayoutItems.Include(x => x.KpiInformations).Single(x => x.Id == request.Id); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; var kpiInformations = new List<DerKpiInformation>(); foreach (var item in request.KpiInformations) { var kpiInformation = DataContext.DerKpiInformations.SingleOrDefault(x => x.Id == item.Id); if (kpiInformation != null) { DataContext.DerKpiInformations.Remove(kpiInformation); } if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } /*if (kpiInformation != null) { DataContext.DerKpiInformations.Remove(kpiInformation); if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } } else { if (item.KpiId > 0) { var kpi = new Kpi { Id = item.KpiId }; if (DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id) == null) { DataContext.Kpis.Attach(kpi); } else { kpi = DataContext.Kpis.Local.FirstOrDefault(x => x.Id == kpi.Id); } var newKpiInformation = item.MapTo<DerKpiInformation>(); newKpiInformation.Kpi = kpi; kpiInformations.Add(newKpiInformation); //kpiInformations.Add(new DerKpiInformation { Kpi = kpi, Position = item.Position, ConfigType = item.ConfigType, KpiLabel = item.KpiLabel, KpiMeasurement = item.KpiMeasurement}); } else if (item.HighlightId > 0) { var selectOption = new SelectOption { Id = item.HighlightId }; if (DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id) == null) { DataContext.SelectOptions.Attach(selectOption); } else { selectOption = DataContext.SelectOptions.Local.FirstOrDefault(x => x.Id == selectOption.Id); } kpiInformations.Add(new DerKpiInformation { SelectOption = selectOption, Position = item.Position, ConfigType = item.ConfigType }); } }*/ } derLayoutItem.KpiInformations = kpiInformations; //DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.Entry(derLayoutItem).State = EntityState.Modified; DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }
private BaseResponse SaveUser(SaveLayoutItemRequest request) { var response = new GetDerLayoutResponse(); try { var derLayoutItem = new DerLayoutItem(); var derLayout = new DerLayout { Id = request.DerLayoutId }; DataContext.DerLayouts.Attach(derLayout); derLayoutItem.DerLayout = derLayout; derLayoutItem.Column = request.Column; derLayoutItem.Row = request.Row; derLayoutItem.Type = request.Type; derLayoutItem.SignedBy = DataContext.Users.Single(x => x.Id == request.SignedBy); DataContext.DerLayoutItems.Add(derLayoutItem); DataContext.SaveChanges(); response.IsSuccess = true; response.Message = "Changes has been saved"; } catch (Exception exception) { response.Message = exception.Message; } return response; }