Пример #1
0
        public IHttpActionResult EditExpenseGroup(int id, [FromBody] ExpenseGroupDto expenseGroupDto)
        {
            try
            {
                if (expenseGroupDto == null)
                {
                    return(BadRequest());
                }

                var result = _unitOfWork.ExpenseGroups.EditExpenseGroup(_mapper.Map <ExpenseGroup>(expenseGroupDto));

                if (result.Status == RepositoryActionStatus.NotFound)
                {
                    return(NotFound());
                }

                if (result.Status == RepositoryActionStatus.Updated)
                {
                    return(Ok(_mapper.Map <ExpenseGroupDto>(result.Entity)));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Пример #2
0
        public OperationResult <ExpenseGroupDto> Create(ExpenseGroupDto expenseGroupDto)
        {
            var workerResult = new OperationResult <ExpenseGroupDto>();

            var expenseGroup  = this.GetExpenseGroupFromExpenseGroupDto(expenseGroupDto);
            var serviceResult = this.expenseGroupService.Add(expenseGroup);

            var createdExpenseGroup = this.GetExpenseGroupDtoFromExpenseGroup(serviceResult.Entity);

            workerResult = this.workerResultBuilder.BuildOperationResult(createdExpenseGroup, serviceResult.OperationResultType, serviceResult.Message);

            return(workerResult);
        }
Пример #3
0
        private ExpenseGroupDto GetExpenseGroupDtoFromExpenseGroup(ExpenseGroup expenseGroup)
        {
            var expenseGroupDto = new ExpenseGroupDto()
            {
                Id             = Guid.Parse(expenseGroup.Id),
                Name           = expenseGroup.Name,
                Active         = expenseGroup.Active,
                CreationDate   = expenseGroup.CreationDate,
                LastUpdateDate = expenseGroup.LastUpdateDate
            };

            return(expenseGroupDto);
        }
Пример #4
0
        private ExpenseGroup GetExpenseGroupFromExpenseGroupDto(ExpenseGroupDto expenseGroupDto)
        {
            var expenseGroup = new ExpenseGroup()
            {
                Id             = expenseGroupDto.Id.ToString(),
                UserId         = expenseGroupDto.UserId.ToString(),
                Name           = expenseGroupDto.Name,
                Active         = expenseGroupDto.Active,
                CreationDate   = expenseGroupDto.CreationDate,
                LastUpdateDate = expenseGroupDto.LastUpdateDate
            };

            return(expenseGroup);
        }
Пример #5
0
        public IHttpActionResult Put([FromBody] ExpenseGroupDto expenseGroup)
        {
            IHttpActionResult actionResult;

            var workerResult = this.expenseGroupWorker.Edit(expenseGroup);

            if (workerResult.OperationResultType == OperationResultType.Success)
            {
                actionResult = Ok(workerResult.Entity);
            }
            else
            {
                actionResult = BadRequest(workerResult.Message);
            }

            return(actionResult);
        }
Пример #6
0
        public IHttpActionResult AddExpenseGroup([FromBody] ExpenseGroupDto expenseGroupDto)
        {
            if (expenseGroupDto == null)
            {
                return(BadRequest());
            }

            var result = _unitOfWork.ExpenseGroups.AddExpenseGroup((_mapper.Map <ExpenseGroup>(expenseGroupDto)));

            if (result.Status == RepositoryActionStatus.Created)
            {
                var newExpenseGroup = _mapper.Map <ExpenseGroupDto>(result.Entity);

                return(Created(Request.RequestUri + "/" + newExpenseGroup.Id.ToString(), newExpenseGroup));
            }

            return(BadRequest());
        }
Пример #7
0
        public OperationResult <ExpenseGroupDto> GetById(Guid id)
        {
            var workerResult = new OperationResult <ExpenseGroupDto>();

            var serviceResult           = this.expenseGroupService.GetById(id);
            var expenseGroupDtoToReturn = new ExpenseGroupDto()
            {
                Id             = Guid.Parse(serviceResult.Entity.Id),
                Name           = serviceResult.Entity.Name,
                Active         = serviceResult.Entity.Active,
                CreationDate   = serviceResult.Entity.CreationDate,
                LastUpdateDate = serviceResult.Entity.LastUpdateDate
            };

            workerResult = this.workerResultBuilder.BuildOperationResult(expenseGroupDtoToReturn,
                                                                         serviceResult.OperationResultType,
                                                                         serviceResult.Message);

            return(workerResult);
        }
Пример #8
0
        public IHttpActionResult Post([FromBody] ExpenseGroupDto expenseGroup)
        {
            IHttpActionResult actionResult;

            var userId = System.Web.HttpContext.Current.User.Identity.GetUserId();

            expenseGroup.UserId = Guid.Parse(userId);

            var workerResult = this.expenseGroupWorker.Create(expenseGroup);

            if (workerResult.OperationResultType == OperationResultType.Success)
            {
                actionResult = Ok(workerResult.Entity);
            }
            else
            {
                actionResult = BadRequest(workerResult.Message);
            }

            return(actionResult);
        }