/// <summary> /// /// </summary> /// <param name="contract"></param> /// <returns></returns> #region PUT public async Task PutChartDataAsync(KpiChartContract contract) { var existing = await Context.KpiCharts.FindAsync(contract.Id); if (existing == null) { throw new CannotFindIdException("chart", contract.Id); } var updated = KPIDashboardMapper.ChartContractToEntity(contract); Context.KpiDataSets.RemoveRange(Context.KpiDataSets.Where(x => x.ChartId == existing.Id)); if (!Context.KpiAdditionalContents.Any(c => c.Id == updated.Id)) { Context.KpiAdditionalContents.Add(updated.AdditionalContent); } else { Context.Entry(updated.AdditionalContent).State = EntityState.Modified; } existing.DataSets = contract.DataSets.Select(KPIDashboardMapper.DataSetContractToEntity).ToList(); Context.Entry(existing).CurrentValues.SetValues(updated); Context.Entry(existing).State = EntityState.Modified; if (await Context.SaveChangesAsync() <= 0) { throw new CannotSaveToDatabaseException("chart"); } }
public async Task <IHttpActionResult> PostChart([FromBody] KpiChartContract contract) { var chartId = await _repository.PostChartDataAsync(contract); return(CreatedAtRoute("ChartDataById", new { id = chartId }, chartId)); }
/// <summary> /// /// </summary> /// <param name="contract"></param> /// <returns></returns> #region POST public async Task <int> PostChartDataAsync(KpiChartContract contract) { if (Context.KpiCharts.Find(contract.Id) != null) { throw new EntityConflictException("chart", contract.Id); } var newChart = KPIDashboardMapper.ChartContractToEntity(contract); var category = Context.KpiCategories.Find(contract.CategoryId); if (category == null) { throw new CannotFindIdException("category", contract.CategoryId); } newChart.DisplayOrder = category.Charts.Count() + 1; Context.KpiCharts.Add(newChart); Context.Entry(newChart).State = EntityState.Added; var isSaved = await Context.SaveChangesAsync(); if (isSaved <= 0) { throw new CannotSaveToDatabaseException("chart"); } return(newChart.Id); }
public async Task <HttpStatusCodeResult> EditKPIChart(KpiChartContract chart) { if (!ModelState.IsValid) { } await _proxy.PutChartDataAsync(chart); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
//[ValidateAntiForgeryToken] public async Task <ActionResult> CreateKPIChart(KpiChartContract chart) { if (!ModelState.IsValid) { } //var additionalInfo = new KpiAdditionalContentContract //{ // ChartId = 0, // Content = "" //}; //chart.AdditionalContent = additionalInfo; var newId = await _proxy.PostChartDataAsync(chart); return(Json(newId)); }
public async Task <IHttpActionResult> PutChart([FromBody] KpiChartContract contract) { await _repository.PutChartDataAsync(contract); return(new NoContentResponse()); }
/// <summary> /// posts new kpi chart /// </summary> /// /// <param KpiDashboardContract="model"></param> /// <returns></returns> public async Task <int> PostChartDataAsync(KpiChartContract chart) { return(await _client.PostWithResultAsync <int>($"{KpiDashboardDiscoveryRoute}/chart", chart)); }
/// <summary> /// puts edited kpi chart /// </summary> /// /// <param KpiDashboardContract="model"></param> /// <returns></returns> public async Task PutChartDataAsync(KpiChartContract chart) { await _client.PutAsync($"{KpiDashboardDiscoveryRoute}/chart", chart); }
/// <summary> /// Map kpi chart contract to database entity /// </summary> /// <param name="contract"></param> /// <param name="id"></param> /// <returns></returns> public static KpiChart ChartContractToEntity(KpiChartContract contract) { var chart = Mapper.Map <KpiChartContract, KpiChart>(contract); return(chart); }