public async Task <ActionResult <WebStoreItemDTO> > CreateWebStoreItem(WebStoreItemDTO webStoreItemDTO) { var webStoreItem = new WebStoreItem { Name = webStoreItemDTO.Name, Description = webStoreItemDTO.Description, Price = webStoreItemDTO.Price, IsAvailable = webStoreItemDTO.IsAvailable, IsDiscounted = webStoreItemDTO.IsDiscounted, Picture = webStoreItemDTO.Picture }; _context.WebStoreItems.Add(webStoreItem); await _context.SaveChangesAsync(); return(CreatedAtAction(nameof(GetWebStoreItem), new { id = webStoreItem.Id }, ItemToDTO(webStoreItem))); }
public async Task <IActionResult> UpdateWebStoreItem(ulong id, WebStoreItemDTO webStoreItemDTO) { if (id != webStoreItemDTO.Id) { return(BadRequest()); } var webStoreItem = await _context.WebStoreItems.FindAsync(id); if (webStoreItem == null) { return(NotFound()); } webStoreItem.Name = webStoreItemDTO.Name; webStoreItem.Description = webStoreItemDTO.Description; webStoreItem.Price = webStoreItemDTO.Price; webStoreItem.IsAvailable = webStoreItemDTO.IsAvailable; webStoreItem.IsDiscounted = webStoreItemDTO.IsDiscounted; webStoreItem.Picture = webStoreItemDTO.Picture; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!WebStoreItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }