public async Task <IActionResult> UpdateCategory(int id, CategoryForUpdateDto categoryForUpdateDto) { if (categoryForUpdateDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var categoryFromRepo = await _repo.GetCategory(id); if (categoryFromRepo == null) { return(NotFound($"Could not find category with an ID of {id}")); } _mapper.Map(categoryForUpdateDto, categoryFromRepo); if (await _unitOfWork.CompleteAsync()) { return(NoContent()); } throw new Exception($"Updating category {id} failed on save"); }
public async Task <IActionResult> UpdateCategory(int categoryId, CategoryForUpdateDto categoryForUpdateDto) { var command = new UpdateCategoryCommand(categoryId, categoryForUpdateDto); var result = await Mediator.Send(command); return(result ? (IActionResult)NoContent() : BadRequest()); }
public async Task <IActionResult> CreateCategory(int hotelId, CategoryForUpdateDto categoryForUpdateDto) { if (categoryForUpdateDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var categoryEntity = _mapper.Map <Category>(categoryForUpdateDto); categoryEntity.HotelId = hotelId; _repo.Add(categoryEntity); if (await _unitOfWork.CompleteAsync()) { var categoryToReturn = _mapper.Map <CategoryForUpdateDto>(categoryEntity); return(CreatedAtRoute("GetCategory", new { id = categoryEntity.Id }, categoryToReturn)); } throw new Exception("Creating the category failed on save"); }
public IResult UpdateCategory(CategoryForUpdateDto categoryForUpdateDto) { var categoryToBeUpdated = _mapper.Map <CategoryTranslation>(categoryForUpdateDto); _categoryTranslationRepository.Update(categoryToBeUpdated); return(new SuccessResult(string.Format(Messages.SuccessfulUpdate, nameof(Category)))); }
public async Task <IActionResult> PutCategory([FromRoute] int id, [FromBody] CategoryForUpdateDto categoryForUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //if (id != category.Id) //{ // return BadRequest(); //} var category = await _repository.GetAsync(id); if (category == null) { return(NotFound()); } _mapper.Map(categoryForUpdateDto, category); if (await _unitOfWork.SaveAsync()) { return(NoContent()); } throw new Exception($"Updating category {id} failed on save"); }
public async Task <IActionResult> UpdateCategory(Guid id, [FromBody] CategoryForUpdateDto category) { var categoryEntity = HttpContext.Items["category"] as Category; _mapper.Map(category, categoryEntity); await _repository.SaveAsync(); return(NoContent()); }
public IActionResult Update(CategoryForUpdateDto categoryForUpdateDto) { var result = categoryService.Update(categoryForUpdateDto); if (result.Success) { return(NoContent()); } return(BadRequest(result.Message)); }
public IResult Update(CategoryForUpdateDto categoryForUpdateDto) { var category = GetById(categoryForUpdateDto.Id).Data; category.Description = categoryForUpdateDto.Description; category.Name = categoryForUpdateDto.Name; category.UpdatedAt = DateTime.Now; categoryDal.Update(category); return(new SuccessResult(Messages.CategoryUpdated)); }
public void Update_WhenUpdatedCategory_ShouldUpdate() { // Arrange var categoryForUpdateDto = new CategoryForUpdateDto(); var mockCategoryDal = new MockCategoryDal().MockUpdate().MockGet(new Category()); var sut = new CategoryManager(mockCategoryDal.Object); // Act sut.Update(categoryForUpdateDto); // Assert mockCategoryDal.VerifyUpdate(Times.Once()); }
private async Task UpdateCategory() { CategoryForUpdateDto categoryForUpdateDto = new CategoryForUpdateDto() { Id = _selectedCategoryId, Description = txtDescription.Text, Name = txtName.Text }; await CategoryService.Update(categoryForUpdateDto); MessageBox.Show(Messages.CategoryUpdated); await LoadCategoryList(); }
public IActionResult UpdateCategory(int categoryId, CategoryForUpdateDto category) { var categoryFromRepo = _categoryRepository.GetCategory(categoryId); if (categoryFromRepo == null) { return(NotFound()); } _mapper.Map(category, categoryFromRepo); _categoryRepository.UpdateCategory(categoryFromRepo); _categoryRepository.Save(); return(NoContent()); }
public void CategoryForUpdateValidator_TrueStory() { // Arrange var model = new CategoryForUpdateDto() { Id = 1, Description = "Desc Category T", Name = "Category T" }; var sut = new CategoryForUpdateValidator(); // Act var result = sut.TestValidate(model); // Assert result.ShouldNotHaveAnyValidationErrors(); }
public static async Task Update(CategoryForUpdateDto categoryForUpdateDto) { using var client = new HttpClient(); var uri = $"{APIAddresses.CategoryService}/{categoryForUpdateDto.Id}"; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FormAccessToken.Token); var response = await client.PutAsJsonAsync(uri, categoryForUpdateDto); if (response.IsSuccessStatusCode) { return; } var errorContent = response.Content.ReadFromJsonAsync <ErrorDetail>().Result; throw new HttpFailureException(errorContent); }
public IActionResult UpdateCategory(Guid categoryId, CategoryForUpdateDto category) { if (!_transactionRepository.IncomeCategoryExists(categoryId) && !_transactionRepository.OutcomeCategoryExists(categoryId)) { return(NotFound()); } var incomeCategoryFromRepo = _transactionRepository.GetIncomeCategory(categoryId); var outcomeCategoryFromRepo = _transactionRepository.GetOutcomeCategory(categoryId); if (incomeCategoryFromRepo != null) { _mapper.Map(category, incomeCategoryFromRepo); } if (outcomeCategoryFromRepo != null) { _mapper.Map(category, outcomeCategoryFromRepo); } _transactionRepository.Save(); return(NoContent()); }
public IActionResult UpdateCategory([FromBody] CategoryForUpdateDto cat) { try { if (cat == null) { _logger.LogError("Category object sent from client is null."); return(BadRequest("Category object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid category object sent from client."); return(BadRequest("Invalid model object")); } var CategoryEntity = _repository.Category.GetCategoryById(cat.id); if (CategoryEntity == null) { _logger.LogError($"Category with id: {cat.id}, hasn't been found in db."); return(NotFound()); } _mapper.Map(cat, CategoryEntity); _repository.Category.UpdateCategory(CategoryEntity); _repository.Save(); return(Ok("Category is updated")); } catch (Exception ex) { _logger.LogError($"Something went wrong inside UpdateCategory action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public UpdateCategoryCommand(int categoryId, CategoryForUpdateDto categoryForUpdateDto) { CategoryForUpdateDto = categoryForUpdateDto; CategoryId = categoryId; }