Exemplo n.º 1
0
        public HttpResponseMessage GetDebtById(int debtId)
        {
            Debt getDebt = new Debt();

            if (debtRepository == null)
            {
                DebtRepository debtRepository = new DebtRepository();
                getDebt = debtRepository.GetDebtById(debtId);

                if (getDebt != null)
                {
                    DebtViewModel    debt       = new DebtViewModel();
                    FriendRepository friendName = new FriendRepository();

                    debt.Id            = getDebt.Id;
                    debt.Value         = getDebt.Value.ToString();
                    debt.Date          = Convert.ToString(getDebt.Date);
                    debt.Description   = getDebt.Description;
                    debt.FriendNameIn  = friendName.GetFriendNameById(getDebt.FriendIdIn).Trim();
                    debt.FriendNameOut = friendName.GetFriendNameById(getDebt.FriendIdOut).Trim();

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

                if (getDebt != null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, getDebt));
                }
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find debt."));
        }