public async Task UpdateAsync(ExpenseCategoryToUpdate model) { var entity = await _repository.GetByIdAsync(model.Id); _mapper.Map(model, entity); await _repository.UpdateAsync(entity); }
private ExpenseCategoryEf ConvertFrom_ExpenseCategoryToUpdate_To_Entity(ExpenseCategoryToUpdate model, ExpenseCategoryEf entity) { var instance = entity ?? new ExpenseCategoryEf(); instance.Name = model.Name.RemoveSpace(); instance.Description = model.Description.RemoveSpace(); return(instance); }
public async Task <IActionResult> Update([FromRoute] int residentialId, [FromRoute] int categoryId, [FromBody] ExpenseCategoryToUpdate category) { if (!ModelState.IsValid) { return(BadRequest()); } var loggedUser = User.GetUserId(); if (!await _userManager.IsAdminAsync(residentialId, loggedUser)) { return(Forbid(_localizer.GetValue(LocalizationMessage.YouDoNotHavePermissionToAccessThisResource))); } if (!await _categoryManager.ExistsAsync(residentialId, categoryId)) { return(NotFound(_localizer.GetValue(LocalizationMessage.CategoryNotFound))); } if (await _categoryManager.ExistsAsync(residentialId, category.Id, category.Name)) { return(BadRequest(_localizer.GetValue(LocalizationMessage.EmailAlreadyExists))); } await _categoryManager.UpdateAsync(category); return(NoContent()); }
private ExpenseCategoryToUpdate ConvertFrom_Entity_To_CategoryToUpdate(ExpenseCategoryEf entity, ExpenseCategoryToUpdate model) { var instance = model ?? new ExpenseCategoryToUpdate(); instance.Id = entity.Id; instance.Name = entity.Name; instance.Description = entity.Description; return(instance); }