Пример #1
0
        public IHttpActionResult Put(int id, [FromBody] ExpenseGroupDTO expensegroup)
        {
            try
            {
                if (expensegroup == null)
                {
                    return(BadRequest());
                }
                var eg = ExpenseGroupFactory.CreateExpenseGroupEntity(expensegroup);

                var result = _repo.UpdateExpenseGroup(eg);
                if (result.Status == RepositoryActionStatus.Updated)
                {
                    var updatedExpenseGroup = ExpenseGroupFactory.CreateExpenseGroupDTO(result.Entity);
                    return(Ok(updatedExpenseGroup));
                }
                else if (result.Status == RepositoryActionStatus.NotFound)
                {
                    return(NotFound());
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Пример #2
0
        public IHttpActionResult Patch(int id, [FromBody] JsonPatchDocument <ExpenseGroupDTO> expenseGroupPatchDocument)
        {
            try
            {
                if (expenseGroupPatchDocument == null)
                {
                    return(BadRequest());
                }

                var expenseGroup = _repo.GetExpenseGroup(id);
                if (expenseGroup == null)
                {
                    return(NotFound());
                }

                var eg = ExpenseGroupFactory.CreateExpenseGroupDTO(expenseGroup);
                expenseGroupPatchDocument.ApplyTo(eg);
                var result = _repo.UpdateExpenseGroup(ExpenseGroupFactory.CreateExpenseGroupEntity(eg));

                if (result.Status == RepositoryActionStatus.Updated)
                {
                    var patchedExpenseGroup = ExpenseGroupFactory.CreateExpenseGroupDTO(result.Entity);
                    return(Ok(patchedExpenseGroup));
                }

                return(BadRequest());
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Пример #3
0
        public IHttpActionResult Post([FromBody] ExpenseGroupDTO expensegroup)
        {
            try
            {
                if (expensegroup == null)
                {
                    return(BadRequest());
                }
                else
                {
                    //no reverse mapping with AutoMap
                    var eg = ExpenseGroupFactory.CreateExpenseGroupEntity(expensegroup);

                    var result = _repo.InsertExpenseGroup(eg);
                    if (result.Status == RepositoryActionStatus.Created)
                    {
                        var newExpenseGroup = ExpenseGroupFactory.CreateExpenseGroupDTO(result.Entity);
                        return(Created <ExpenseGroupDTO>(Request.RequestUri + "/" + newExpenseGroup.Id.ToString(), newExpenseGroup));
                    }
                    return(BadRequest());
                }
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }