public IActionResult Put([FromRoute] string id, [FromBody] EditProductCategoryDto productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Put(id, productCategory);

            return(NoContent());
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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;
                }
            }
        }
Exemplo n.º 5
0
 public Task Put(int categoryId, [FromBody] EditProductCategoryDto category)
 {
     return(_categoriesService.UpdateCategoryAsync(categoryId, category, HttpContext.RequestAborted));
 }
Exemplo n.º 6
0
 public Task Post(int?parentCategoryId, [FromBody] EditProductCategoryDto category)
 {
     return(_categoriesService.AddCategoryAsync(parentCategoryId, category, HttpContext.RequestAborted));
 }