Ejemplo n.º 1
0
        public async Task <IActionResult> Put(
            [FromServices] ITransactionBO transactionBO,
            string id,
            [FromBody] Transaction transaction)
        {
            try
            {
                int result = await transactionBO.Update(id, transaction);

                if (result == 1)
                {
                    return(NoContent());
                }
                else
                {
                    return(UnprocessableEntity("Error on update"));
                }
            }
            catch (Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException e)
            {
                return(NotFound(e.Message));
            }
            catch (DbException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (Exceptions.NotFoundException e)
            {
                return(NotFound("Not Found"));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Post(
            [FromServices] ITransactionBO transactionBO,
            [FromBody] Transaction transaction)
        {
            try
            {
                int result = await transactionBO.Save(transaction);

                if (result == 1)
                {
                    return(CreatedAtAction(null, null));
                }
                else
                {
                    return(UnprocessableEntity("Error on create"));
                }
            }
            catch (DbException e)
            {
                return(UnprocessableEntity(e.Message));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Delete(
            [FromServices] ITransactionBO transactionBO,
            string id)
        {
            try
            {
                int result = await transactionBO.Delete(id);

                if (result == 1)
                {
                    return(NoContent());
                }
                else
                {
                    return(UnprocessableEntity("Error on delete"));
                }
            }
            catch (Exceptions.NotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <IEnumerable <Transaction> > > GetByUserId(
            [FromServices] ITransactionBO transactionBO,
            string userId)
        {
            try
            {
                var transactions = await transactionBO.GetByUserId(userId, 20);

                return(Ok(transactions));
            }
            catch (Exceptions.NotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (System.Exception e)
            {
                return(BadRequest(e.Message));
            }
        }