public async Task <IActionResult> PostInflationRate([FromBody] InflationRate inflationRate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.InflationRates.Add(inflationRate); await _context.SaveChangesAsync(); //var createdInflationRate = _context.InflationRates.Include(eR => eR.Year).Include(e => e.Month).Select(xc => new YearViewModel //{ // ID = xc.ID, // YearId = xc.Year.ID, // Rate = xc.Rate, // Name = xc.Year.Name //}).FirstOrDefault(e => e.ID == inflationRate.ID); return(Ok()); }
public async Task <IActionResult> PutInflationRate([FromRoute] int id, [FromBody] InflationRate inflationRate) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != inflationRate.ID) { return(BadRequest()); } _context.Entry(inflationRate).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!InflationRateExists(id)) { return(NotFound()); } else { throw; } } var rates = _context.InflationRates.Include(iR => iR.Year).Include(eR => eR.Month).Select(xc => new YearViewModel { ID = xc.ID, YearId = xc.Year.ID, Rate = xc.Rate, Name = xc.Year.Name }).FirstOrDefault(xz => xz.ID == inflationRate.ID); return(Ok(rates)); }