public async Task UpdateProductCategory(ProductCategoryUpdateDto input) { var productCategory = await _productCategoryRepository.GetAllIncluding(p => p.Translations) .FirstOrDefaultAsync(p => p.Id == input.Id); productCategory.Translations.Clear(); ObjectMapper.Map(input, productCategory); }
public async Task <IActionResult> Update([FromBody] ProductCategoryUpdateDto model) { var result = await _productCategoryService.Update(model); if (result.Message != ApiResultMessages.Ok) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <ActionResult> UpdateCategory([FromBody] ProductCategoryUpdateDto model) { try { if (UserResolverService.IsUserAdmin()) { await ProductService.UpdateCategory(model); return(NoContent()); } return(Forbid()); } catch (Exception ex) { return(BadRequest(new { message = ex.Message })); } }
public async Task <ApiResult> Update(ProductCategoryUpdateDto model) { var entity = await _context.ProductCategory .Where(x => !x.IsDeleted && x.Id == model.Id) .FirstOrDefaultAsync(); if (entity == null) { return new ApiResult { Data = model.Id, Message = ApiResultMessages.PCE01 } } ; entity.Name = model.Name; await _context.SaveChangesAsync(); return(new ApiResult { Data = entity.Id, Message = ApiResultMessages.Ok }); }
public async Task UpdateCategory(ProductCategoryUpdateDto model) { var category = await _productCategoryRepository.FindByCondition(c => c.Id == model.Id); if (category == null) { throw new Exception($"There is no category with id = {model.Id} in database"); } else { category.Name = model.Name; } await _productCategoryRepository.UpdateAsync(category); var affectedRows = await _productCategoryRepository.SaveChangesAsync(); if (affectedRows == 0) { throw new DbUpdateException(); } }