public async Task <IActionResult> DeleteSupplies(ApiSupplies apiSupplies) { var currentUserId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (apiSupplies.UserId != currentUserId) { return(Unauthorized()); } var deletedSupplies = Supplies.FromApiSupplies(apiSupplies); _context.Entry(deletedSupplies).State = EntityState.Deleted; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SuppliesExists(deletedSupplies)) { return(NotFound()); } throw; } return(NoContent()); }
public async Task <ActionResult <ApiSupplies> > PostApiSupplies(ApiSupplies apiSupplies) { var currentUserId = _httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (apiSupplies.UserId != currentUserId) { return(Unauthorized()); } var supplies = Supplies.FromApiSupplies(apiSupplies); await _context.Supplies.AddAsync(supplies); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (SuppliesExists(supplies)) { return(Conflict()); } throw; } return(CreatedAtAction("GetSuppliedIngredients", new { id = apiSupplies.IngrName }, apiSupplies)); }