public async Task<IHttpActionResult> PutUserStock(int id, UserStock userStock) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != userStock.ID) { return BadRequest(); } var dbUserStock = await _db.UserStocks.FindAsync(id); if (dbUserStock == null) return NotFound(); if (dbUserStock.User.ToLower() != _currentUser.ToLower()) { return BadRequest("Cannot edit other users stock."); } _db.MarkAsModified(userStock); await _db.SaveChangesAsync(); return StatusCode(HttpStatusCode.NoContent); }
public async Task<IHttpActionResult> PostUserStock(UserStockDto dto) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var userStock = new UserStock { Name = dto.Name, User = _currentUser }; _db.UserStocks.Add(userStock); await _db.SaveChangesAsync(); return CreatedAtRoute("DefaultApi", new { id = userStock.ID }, userStock); }