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()); } }
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); }
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); }
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); }
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); }
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()); }
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); }
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); }