public IActionResult Put([FromRoute] string id, [FromBody] EditProductCategoryDto productCategory) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.Put(id, productCategory); return(NoContent()); }
public async Task AddCategoryAsync(int?parentId, EditProductCategoryDto category, CancellationToken cancellationToken = default(CancellationToken)) { var c = new ProductCategory { Name = category.Name, ParentId = parentId }; try { _dbContext.Add(c); await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateException ex) { throw new InvalidItemException(c, ex); } }
public async Task UpdateCategoryAsync(int id, EditProductCategoryDto category, CancellationToken cancellationToken = default(CancellationToken)) { var c = new ProductCategory { Id = id, Name = category.Name }; _dbContext.Attach(c).State = EntityState.Modified; try { await _dbContext.SaveChangesAsync(cancellationToken); } catch (DbUpdateConcurrencyException ex) { throw new ItemNotFoundException(id, "Category", ex); } catch (DbUpdateException ex) { throw new InvalidItemException(c, ex); } }
public void Put(string id, EditProductCategoryDto dto) { var productCategory = _context.ProductCategory.Get(id); Mapper.Map(dto, productCategory); _context.ProductCategory.Update(productCategory); try { _context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!ProductCategoryExists(id)) { //return NotFound(); } else { throw; } } }
public Task Put(int categoryId, [FromBody] EditProductCategoryDto category) { return(_categoriesService.UpdateCategoryAsync(categoryId, category, HttpContext.RequestAborted)); }
public Task Post(int?parentCategoryId, [FromBody] EditProductCategoryDto category) { return(_categoriesService.AddCategoryAsync(parentCategoryId, category, HttpContext.RequestAborted)); }