public async Task <ActionResult> UpdateEdition(int id, int editionId, [FromBody] ProductEditionDTO editionDto) { try { var item = _context.Products .Where(o => o.Id == id) .Include(r => r.ProductEditions) .FirstOrDefault(); if (item == null) { return(await Task.Run(() => NotFound())); } var orgEdition = item.ProductEditions .Where(a => a.Id == editionId) .FirstOrDefault(); if (orgEdition == null) { return(await Task.Run(() => NotFound())); } orgEdition = _mapper.Map(editionDto, orgEdition); _context.SaveChanges(); return(await Task.Run(() => new ObjectResult(editionDto))); } catch (Exception ex) { var x = ex.Message; throw; } }
public async Task <ActionResult> AddEdition(int id, [FromBody] ProductEditionDTO editionDto) { var item = _context.Products .Where(o => o.Id == id) .Include(r => r.ProductEditions) .FirstOrDefault(); if (item == null) { return(await Task.Run(() => NotFound())); } editionDto.Created = DateTime.Now; var edition = _mapper.Map <ProductEdition>(editionDto); item.ProductEditions.Add(edition); _context.SaveChanges(); editionDto = _mapper.Map <ProductEditionDTO>(edition); return(await Task.Run(() => new ObjectResult(editionDto))); }