public async Task <bool> EditCategoryAsync(EditCategoryDto editCategory) { var category = await _dbContext.Categories.FindAsync(editCategory.Id); category.Name = editCategory.Name; return(await _dbContext.SaveChangesAsync() > 0); }
public async Task <IActionResult> UpdateCategory(EditCategoryDto categoryDto) { var updateCategory = await mediator.Send(new UpdateCategoryCommand { Id = categoryDto.Id, Name = categoryDto.Name, ParentId = categoryDto.ParentId }); if (updateCategory.Success) { return(Ok(updateCategory.Result)); } return(BadRequest(updateCategory.ErrorMessage)); }
public async Task <Category> GetCategory(EditCategoryDto model) { // if(model.Id==null)return null; var category = await _db.Categories.FirstOrDefaultAsync(x => x.Id == model.Id); if (category == null) { return(null); } return(category); }
public async Task <IActionResult> EditCategory([FromRoute] int id, EditCategoryDto model) { var category = await _Repo.GetCategory(id); _mapper.Map(model, category); if (await _Repo.SaveAll()) { return(NoContent()); } throw new Exception($"ff"); }
public ActionResult EditCategory(EditCategoryDto model) { try { //Check the model state if (!ModelState.IsValid) { ViewBag.Parents = LoadParents(); ViewBag.TypesOfPayments = LoadTypesOfPayments(); return(View(model)); } //Make sure title and slug are unique if (_categoryRepository.GetAll().Where(x => x.Id != model.Id).Any(x => x.Title == model.Title)) { ViewBag.Parents = LoadParents(); ModelState.AddModelError("CustomError", "קטגוריה זו כבר קיימת."); ViewBag.TypesOfPayments = LoadTypesOfPayments(); return(View(model)); } //Get the Sentence Category dto = _categoryRepository.Get(model.Id); if (dto == null) { return(Content("הקטגוריה לא קיימת")); } else { dto = Mapper.Map <Category>(model); //Update dto object _categoryRepository.Update(dto); ViewBag.TypesOfPayments = LoadTypesOfPayments(); ViewBag.Parents = LoadParents(); InitState(); return(View(model)); } } catch (Exception ex) { logger.Error($"EditSentence() {DateTime.Now}"); logger.Error(ex.Message); logger.Error("=============================="); return(null); } }
public async Task <ActionResult> Edit(int id, [FromBody] EditCategoryDto input) { if (id <= 0) { return(BadRequest("Invalid Category Id")); } var category = await _unitOfWork.GetRepo <Category>().GetByID(id); if (category == null) { return(NotFound("There is no Category with the specified Id")); } category.Edit(input.Name); if (await _unitOfWork.Complete()) { return(Ok()); } return(BadRequest($"Failed to edit category with Id : {id}")); }
public async Task <IActionResult> EditCategory([FromBody] EditCategoryDto category) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!await _categoryRepository.CategoryExistsAsync(category.Id)) { ModelState.AddModelError("category", "Category not found"); return(BadRequest(ModelState)); } if (await _categoryRepository.IsDuplicateCategoryAsync(category)) { ModelState.AddModelError("category", "Category already exists"); return(BadRequest(ModelState)); } var wasCategoryEdited = await _categoryRepository.EditCategoryAsync(category); if (wasCategoryEdited) { return(Ok()); } return(NoContent()); } catch (Exception e) { _logger.LogCritical($"PUT {Route} - {e.GetType().Name} - {e.Message} - {e.StackTrace}"); return(StatusCode(500, "An error ocurred in server")); } }
public async Task <bool> IsDuplicateCategoryAsync(EditCategoryDto category) { return(await _dbContext.Categories.AnyAsync(c => c.Name.Equals(category.Name, StringComparison.InvariantCultureIgnoreCase) && c.Id != category.Id && c.IsActive)); }
public async Task <IActionResult> Edit([FromBody] EditCategoryDto input) { await _categoryService.EditCategories(input); return(Ok()); }
public async Task EditCategories(EditCategoryDto input) { //Admin: Kategori düzenleme var category = _mapper.Map <Category>(input); await _repository.UpdateAsync(category); }