Ejemplo n.º 1
0
        public HttpResponseMessage UpdateDebt([FromBody] DebtViewModel debtAttribute, [FromUri] int debtId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateUpdateDebt(debtAttribute, debtId);

            if (Message == String.Empty)
            {
                Debt             debt       = new Debt();
                FriendRepository friendName = new FriendRepository();
                Boolean          sucess;

                if (debtRepository == null)
                {
                    DebtRepository debtRepository = new DebtRepository();

                    debt = debtRepository.GetDebtById(debtId);

                    if (debt != null)
                    {
                        debtAttribute.Id = debtId;
                        debt.Value       = Convert.ToDecimal(debtAttribute.Value);
                        debt.Date        = Convert.ToDateTime(debtAttribute.Date);
                        debt.Description = debtAttribute.Description;
                        debt.FriendIdIn  = friendName.GetFriendIdByName(debtAttribute.FriendNameIn);
                        debt.FriendIdOut = friendName.GetFriendIdByName(debtAttribute.FriendNameOut);

                        sucess = debtRepository.Update(debt, debtId);

                        if (sucess)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, debtAttribute));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not update debt."));
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
                    }
                }
                else
                {
                    debt   = debtRepository.GetDebtById(debtId);
                    sucess = debtRepository.Update(debt, debtId);

                    if (sucess)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, debt));
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
            }
        }
Ejemplo n.º 2
0
 public void Update(int debtId, UpdateDebtDTO updatedDebt)
 {
     try
     {
         _debtRepository.Update(debtId, updatedDebt);
     }
     catch (Exception e)
     {
         throw new Exception($"Houve um problema ao fazer esta operação.\n-> {e.Message}");
     }
 }
Ejemplo n.º 3
0
        public async Task Update(UpdateDebtRequest request)
        {
            Debtor debtor = await _debtorRepository.GetById(request.DebtorId);

            if (debtor is null)
            {
                throw new AppCustomException(StatusCodes.Status400BadRequest, "Debtor does not exist");
            }
            Debt debt = _mapper.Map <UpdateDebtRequest, Debt>(request);
            await _debtRepository.Update(debt);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Debt> > PutDebt(long id, [FromBody] Debt debt)
        {
            if (id != debt.Id)
            {
                return(BadRequest());
            }

            await _service.recalculate(debt);

            _respository.Update(debt);
            await _respository.Save();

            return(Ok(debt));
        }