Пример #1
0
        public IActionResult CreateExpenditureType(CreateExpenditureTypeDto createExpenditure)
        {
            var result = _expenditureService.CreateExpenditureType(createExpenditure);

            if (!result.IsSuccess)
            {
                return(BadRequest(result));
            }

            return(Ok(result.Response));
        }
Пример #2
0
        public ServiceResult <CreateExpenditureTypeDto> CreateExpenditureType(CreateExpenditureTypeDto expenditure)
        {
            var validation = _fluentValidator.Validate(expenditure);

            if (!validation.IsValid)
            {
                return(_mapper.Map <ServiceResult <CreateExpenditureTypeDto> >(validation.ToServiceResult <CreateExpenditureTypeDto>(null)));
            }

            ExpenditureType newExpenditure = new ExpenditureType()
            {
                Id          = new Guid(),
                Name        = expenditure.Name,
                CanRepeat   = expenditure.CanRepeat,
                IsImportant = expenditure.IsImportant
            };

            _dataContext.ExpenditureTypes.Add(newExpenditure);
            _dataContext.SaveChanges();

            return(new ServiceResult <CreateExpenditureTypeDto>(expenditure));
        }