public async Task <IActionResult> Edit(CategoryEditViewModel model) { try { if (!ModelState.IsValid) { return(BadRequest()); } var request = new EditCategoryRequest(model.Id) { RouteName = model.RouteName, Note = model.Note, DisplayName = model.DisplayName }; await _categoryService.UpdateAsync(request); DeleteOpmlFile(); return(Json(model)); } catch (Exception e) { Logger.LogError(e, "Error Create Category."); ModelState.AddModelError("", e.Message); return(ServerError()); } }
public static Category ToCategoryModel(this EditCategoryRequest request) { return(new Category { Name = request.Name }); }
public async Task <ActionResult> EditGenre(int categoryId, [FromBody] EditCategoryRequest request) { var genreModel = request.ToCategoryModel(); await _categoryService.Edit(categoryId, genreModel); return(Ok()); }
public async Task <IActionResult> Edit(EditCategoryRequest request) { if (!ModelState.IsValid) { return(Failure()); } return(await _categoryService.Edit(request)); }
public async Task <IActionResult> Update([NotEmpty] Guid id, EditCategoryRequest model) { var oc = await _mediator.Send(new UpdateCategoryCommand(id, model)); if (oc == OperationCode.ObjectNotFound) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> Update([NotEmpty] Guid id, EditCategoryRequest model) { var oc = await _catService.UpdateAsync(id, model.DisplayName, model.RouteName, model.Note); if (oc == OperationCode.ObjectNotFound) { return(NotFound()); } return(NoContent()); }
public async Task <IActionResult> EditCategory([FromBody] EditCategoryRequest editCategoryRequest) { var editedCategory = await _shopService.EditCategoryAsync(editCategoryRequest); if (!editedCategory.Success) { return(BadRequest(editedCategory.Errors)); } return(Ok(editedCategory.Response)); }
public async Task Create_ValidModel() { var categoryController = CreateCategoryController(); var model = new EditCategoryRequest { DisplayName = FakeData.ShortString2, RouteName = FakeData.ShortString2, Note = FakeData.ShortString1 }; var result = await categoryController.Create(model); Assert.IsInstanceOf <CreatedResult>(result); }
public async Task <IActionResult> Edit([FromBody] EditCategoryRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var response = await _categoryService.EditAsync(request); if (!response.IsValid) { return(BadRequest(response.Message)); } return(Ok(response)); }
public async Task <BaseResponse> EditAsync(EditCategoryRequest request) { var category = await _categoryRepository.GetAsync(category => category.Id == request.Id); if (category == null) { return(new BaseResponse("Category is not found")); } category.Name = request.Name; _categoryRepository.Update(category); await _unitOfWork.SaveChangesAsync(); return(new BaseResponse()); }
public async Task <IActionResult> Edit(EditCategoryRequest request) { var category = _context.Categories.Where(i => i.Id == request.CategoryId).FirstOrDefault(); if (category == null) { return(Failure()); } if (category.IsDefault) { return(Failure()); } category.Name = request.Name; await _context.SaveChangesAsync(); return(Success(ConvertToVM(category))); }
public async Task <BaseResponse> EditAsync(EditCategoryRequest request, int accountId) { var category = await _categoryRepository.GetAsync(category => category.Id == request.Id && category.AccountId == accountId); if (category == null) { return(new BaseResponse("Category is not found")); } category.Title = request.Title; category.Description = request.Description; category.PlannedBudget = request.PlannedBudget; _categoryRepository.Update(category); await _unitOfWork.SaveChangesAsync(); return(new BaseResponse()); }
public async Task <IActionResult> Edit(CategoryEditViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var request = new EditCategoryRequest(model.Id) { RouteName = model.RouteName, Note = model.Note, DisplayName = model.DisplayName }; await _categoryService.UpdateAsync(request); return(Ok(model)); }
public async Task Update_ValidModel() { _mockCategoryService .Setup(p => p.UpdateAsync(It.IsAny <Guid>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(Task.FromResult(OperationCode.Done)); var categoryController = CreateCategoryController(); var model = new EditCategoryRequest { DisplayName = FakeData.ShortString2, RouteName = FakeData.ShortString2, Note = FakeData.ShortString1 }; var result = await categoryController.Update(FakeData.Uid1, model); Assert.IsInstanceOf <NoContentResult>(result); }
public async Task Update_NotFound() { _mockMediator .Setup(p => p.Send(It.IsAny <UpdateCategoryCommand>(), default)) .Returns(Task.FromResult(OperationCode.ObjectNotFound)); var categoryController = CreateCategoryController(); var model = new EditCategoryRequest { DisplayName = FakeData.ShortString2, RouteName = FakeData.ShortString2, Note = FakeData.ShortString1 }; var result = await categoryController.Update(FakeData.Uid1, model); Assert.IsInstanceOf <NotFoundResult>(result); }
public async Task UpdateAsync(EditCategoryRequest editCategoryRequest) { var cat = await _categoryRepository.GetAsync(editCategoryRequest.Id); if (null == cat) { return; } cat.RouteName = editCategoryRequest.RouteName.Trim(); cat.DisplayName = editCategoryRequest.DisplayName.Trim(); cat.Note = editCategoryRequest.Note.Trim(); await _categoryRepository.UpdateAsync(cat); _cache.Remove(CacheDivision.General, "allcats"); await _blogAudit.AddAuditEntry(EventType.Content, AuditEventId.CategoryUpdated, $"Category '{editCategoryRequest.Id}' updated."); }
public async Task <ResponseResult <CategoryResponse> > EditCategoryAsync(EditCategoryRequest editCategory) { var editedCategory = await _shopRepository.EditCategoryAsync(editCategory.CategoryId, editCategory.NewRuTitle, editCategory.NewEnTitle); if (editedCategory == null) { return(new ResponseResult <CategoryResponse> { Errors = new[] { "Category not found" } }); } var mappedEditedCategory = _mapper.Map <CategoryResponse>(editedCategory); return(new ResponseResult <CategoryResponse> { Success = true, Response = mappedEditedCategory }); }
public Response UpdateCategory(EditCategoryRequest editCategoryRequest) { return(TryExecute(() => { var cat = _categoryRepository.Get(editCategoryRequest.Id); if (null == cat) { return new Response { Message = $"CategoryEntity id {editCategoryRequest.Id} not found." } } ; cat.Title = editCategoryRequest.Title; cat.DisplayName = editCategoryRequest.DisplayName; cat.Note = editCategoryRequest.Note; var rows = _categoryRepository.Update(cat); return new Response(rows > 0); })); }
/// <summary> /// EditCategory /// </summary> /// <param name="request">EditCategoryRequest</param> /// <returns>bool</returns> public async Task <bool> EditCategory(EditCategoryRequest request) { bool result = false; try { var param = new UpdateCategoryParameter() { id = request.id, nameCategory = request.nameCategory, imgCategory = request.imgCategory }; _dataAccess.EditCategory(param); result = true; return(result); } catch (Exception) { result = false; } return(await Task.FromResult(result)); }
public async Task <CategoryResponse> EditCategoryAsync(EditCategoryRequest request) { if (request == null) { throw new ArgumentNullException(); } var categoryExists = await _categoryRepository.GetAsync(request.Id); if (categoryExists == null) { throw new ArgumentException("News with id {request.Id} does not exist"); } var category = _mapper.Map <Entities.Category>(request); var result = _categoryRepository.Update(category); await _categoryRepository.UnitOfWork.SaveChangesAsync(); var response = _mapper.Map <CategoryResponse>(result); return(response); }
public IActionResult Edit(CategoryEditViewModel model) { try { if (ModelState.IsValid) { var request = new EditCategoryRequest(model.Id) { Title = model.Name, Note = model.Note, DisplayName = model.DisplayName }; var response = _categoryService.UpdateCategory(request); if (response.IsSuccess) { DeleteOpmlFile(); _moongladeAudit.AddAuditEntry(EventType.Content, EventId.CategoryUpdated, $"Category '{model.Id}' is updated"); return(Json(response)); } Logger.LogError($"Edit category failed: {response.Message}"); ModelState.AddModelError("", response.Message); return(BadRequest()); } return(BadRequest()); } catch (Exception e) { Logger.LogError(e, "Error Create Category."); ModelState.AddModelError("", e.Message); return(ServerError()); } }
public Task <Response> UpdateAsync(EditCategoryRequest editCategoryRequest) { return(TryExecuteAsync(async() => { var cat = await _categoryRepository.GetAsync(editCategoryRequest.Id); if (null == cat) { return new Response { Message = $"CategoryEntity id '{editCategoryRequest.Id}' not found." } } ; cat.RouteName = editCategoryRequest.RouteName.Trim(); cat.DisplayName = editCategoryRequest.DisplayName.Trim(); cat.Note = editCategoryRequest.Note.Trim(); await _categoryRepository.UpdateAsync(cat); await _moongladeAudit.AddAuditEntry(EventType.Content, AuditEventId.CategoryUpdated, $"Category '{editCategoryRequest.Id}' updated."); return new SuccessResponse(); })); }
public IActionResult Edit(CategoryEditViewModel model) { try { if (ModelState.IsValid) { var request = new EditCategoryRequest(model.Id) { Title = model.Name, Note = model.Note, DisplayName = model.DisplayName }; var response = _categoryService.UpdateCategory(request); if (response.IsSuccess) { DeleteOpmlFile(); return(RedirectToAction(nameof(Manage))); } Logger.LogError($"Edit category failed: {response.Message}"); ModelState.AddModelError("", response.Message); return(View("CreateOrEdit", model)); } return(View("CreateOrEdit", model)); } catch (Exception e) { Logger.LogError(e, "Error Create Category."); ModelState.AddModelError("", e.Message); return(View("CreateOrEdit", model)); } }
public async Task <IActionResult> Edit(CategoryEditViewModel model) { try { if (ModelState.IsValid) { var request = new EditCategoryRequest(model.Id) { RouteName = model.RouteName, Note = model.Note, DisplayName = model.DisplayName }; var response = await _categoryService.UpdateAsync(request); if (response.IsSuccess) { DeleteOpmlFile(); return(Json(response)); } Logger.LogError($"Edit category failed: {response.Message}"); ModelState.AddModelError("", response.Message); return(Conflict(ModelState)); } return(BadRequest()); } catch (Exception e) { Logger.LogError(e, "Error Create Category."); ModelState.AddModelError("", e.Message); return(ServerError()); } }
public CreateCategoryCommand(EditCategoryRequest payload) { Payload = payload; }
public async Task <IActionResult> Create(EditCategoryRequest model) { await _catService.CreateAsync(model.DisplayName, model.RouteName, model.Note); return(Created(string.Empty, model)); }
public async Task <IActionResult> Update(EditCategoryRequest request) { var result = await _categoryService.EditCategoryAsync(request); return(Ok(result)); }
public async Task <IActionResult> EditCategory([FromRoute(Name = "category_id")] Guid categoryId, [FromBody] EditCategoryRequest request) { // validate input if (!ModelState.IsValid) { return(HttpResult.BadRequest(ModelState)); } // locate category var foundCategory = await _bagsContext.TagCategories .Where(category => category.Id == categoryId) .SingleOrDefaultAsync(); if (foundCategory == null) { return(HttpResult.NotFound()); } // verify there are actual changes if (foundCategory.Name == request.Name) { return(HttpResult.Ok(foundCategory.ToBaseWireFormat())); } // verify no conflicts with unique constraint var duplicateCategory = await _bagsContext.TagCategories .Where(category => category.Name == request.Name) .SingleOrDefaultAsync(); if (duplicateCategory != null) { return(HttpResult.Conflict(duplicateCategory.ToBaseWireFormat())); } // change the name foundCategory.Name = request.Name; await _bagsContext.SaveChangesAsync(); return(HttpResult.Ok(foundCategory.ToBaseWireFormat())); }
public async Task <IActionResult> Create(EditCategoryRequest model) { await _mediator.Send(new CreateCategoryCommand(model)); return(Created(string.Empty, model)); }
public UpdateCategoryCommand(Guid id, EditCategoryRequest payload) { Id = id; Payload = payload; }