public async Task <ActionResult <PriceGrid> > PostPriceGrid(PriceGrid priceGrid) { _context.PriceGrids.Add(priceGrid); await _context.SaveChangesAsync(); return(CreatedAtAction("GetPriceGrid", new { id = priceGrid.Id }, priceGrid)); }
public async Task <IActionResult> PutPriceGrid(int id, PriceGrid priceGrid) { if (id != priceGrid.Id) { return(BadRequest()); } _context.Entry(priceGrid).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PriceGridExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void PopulateIfNecessary(PriceGrid priceGrid) { if (_context.PriceGridEntries.Count(pge => pge.PriceGrid == priceGrid) == 0) { foreach (string symbol in _symbols) { _context.PriceGridEntries.Add(new PriceGridEntry { PriceGrid = priceGrid, Symbol = symbol }); } _context.SaveChanges(); } }
private PriceGrid GetOrCreatePriceGrid(User user, string name) { var priceGrid = _context.PriceGrids.FirstOrDefault(pg => pg.Owner == user && pg.Name == name); if (priceGrid == null) { priceGrid = new PriceGrid { Owner = user, Name = name }; _context.PriceGrids.Add(priceGrid); _context.SaveChanges(); } return(priceGrid); }