コード例 #1
0
        public async Task <IActionResult> Add([FromRoute] int residentialId, [FromBody] ExpenseCategoryToAdd category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var loggedUser = User.GetUserId();

            if (!await _userManager.IsAdminAsync(residentialId, loggedUser))
            {
                return(Forbid(_localizer.GetValue(LocalizationMessage.YouDoNotHavePermissionToAccessThisResource)));
            }

            if (!await _residentialManager.ExistsAsync(residentialId))
            {
                return(NotFound(_localizer.GetValue(LocalizationMessage.ResidentialNotFound)));
            }

            if (await _categoryManager.ExistsAsync(residentialId, category.Name))
            {
                return(BadRequest(_localizer.GetValue(LocalizationMessage.CategoryNameAlreadyExists)));
            }

            await _categoryManager.AddAsync(category);

            return(NoContent());
        }
コード例 #2
0
        private ExpenseCategoryEf ConvertFrom_ExpenseCategoryToAdd_To_Entity(ExpenseCategoryToAdd model, ExpenseCategoryEf entity)
        {
            var instance = entity ?? new ExpenseCategoryEf();

            instance.Name          = model.Name.RemoveSpace();
            instance.Description   = model.Description.RemoveSpace();
            instance.ResidentialId = model.ResidentialId;

            return(instance);
        }
コード例 #3
0
        public async Task AddAsync(ExpenseCategoryToAdd model)
        {
            var entity = _mapper.Map <ExpenseCategoryEf>(model);

            await _repository.AddAsync(entity);
        }