public async Task UpdateAsync(ExpenseCategoryToUpdate model)
        {
            var entity = await _repository.GetByIdAsync(model.Id);

            _mapper.Map(model, entity);

            await _repository.UpdateAsync(entity);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
        }