public HttpResponseMessage CreateFriend([FromBody] FriendViewModel friendAttribute)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            var Message = validates.ValidateFriend(friendAttribute);

            if (Message == String.Empty)
            {
                if (friendRepository == null)
                {
                    FriendRepository friendRepository = new FriendRepository();
                }

                Friend friend = new Friend();
                friend.Name = friendAttribute.Name.Trim();
                friend.Sex  = friendAttribute.Sex;
                friend.Age  = Convert.ToInt32(friendAttribute.Age);

                Boolean sucess = friendRepository.Insert(friend);

                if (sucess)
                {
                    return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create()));
                }
            }
            return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
        }
        public HttpResponseMessage DeleteFriendById([FromUri] int friendId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateDelete(friendId);

            if (Message == String.Empty)
            {
                Friend friend = new Friend();

                if (friendRepository == null)
                {
                    FriendRepository friendRepository = new FriendRepository();
                    friend = friendRepository.GetFriendById(friendId);

                    if (friend != null)
                    {
                        Boolean sucess = friendRepository.DeleteObject(friend, true);

                        if (sucess)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.NoContent));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not delete record."));
                    }
                }
                else
                {
                    friend = friendRepository.GetFriendById(friendId);
                    friendRepository.DeleteObject(friend, true);
                }
                return(new HttpResponseMessage(HttpStatusCode.NoContent));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Message));
        }
Exemplo n.º 3
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));
            }
        }
        public HttpResponseMessage UpdateFriend([FromBody] FriendViewModel friendAttribute, [FromUri] int friendId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            var Message = validates.ValidateUpdateFriend(friendAttribute, friendId);

            if (Message == String.Empty)
            {
                Friend friend = new Friend();

                if (friendRepository == null)
                {
                    FriendRepository friendRepository = new FriendRepository();
                    friend = friendRepository.GetFriendById(friendId);
                }

                if (friend != null)
                {
                    friendAttribute.Id = friendId;
                    friend.Name        = friendAttribute.Name.Trim();
                    friend.Sex         = friendAttribute.Sex;
                    friend.Age         = Convert.ToInt32(friendAttribute.Age);

                    Boolean sucess = false;

                    if (friendRepository == null)
                    {
                        FriendRepository friendRepository = new FriendRepository();
                        sucess = friendRepository.Update(friend, friendId);
                    }
                    else
                    {
                        friend = friendRepository.GetFriendById(friendId);
                        sucess = friendRepository.Update(friend, friendId);
                    }

                    if (sucess)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, friendAttribute));
                    }
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find friend."));
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find friend."));
                }
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage UpdatePayment([FromBody] PaymentViewModel paymentAttribute, [FromUri] int paymentId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateUpdatePayment(paymentAttribute, paymentId);

            if (Message == String.Empty)
            {
                Payment payment = new Payment();

                if (paymentRepository == null)
                {
                    PaymentRepository paymentRepository = new PaymentRepository();
                    payment = paymentRepository.GetPaymentById(paymentId);

                    if (payment != null)
                    {
                        paymentAttribute.Id = paymentId;
                        payment.Value       = Convert.ToDecimal(paymentAttribute.Value);
                        FriendRepository friendName = new FriendRepository();
                        payment.FriendIdIn  = friendName.GetFriendIdByName(paymentAttribute.FriendNameIn);
                        payment.FriendIdOut = friendName.GetFriendIdByName(paymentAttribute.FriendNameOut);

                        Boolean sucess = paymentRepository.Update(payment, paymentId);

                        if (sucess)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, paymentAttribute));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not update payment."));
                    }
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not find payment."));
                }
                else
                {
                    payment = paymentRepository.GetPaymentById(paymentId);
                    paymentRepository.Update(payment, paymentId);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, payment));
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
            }
        }
Exemplo n.º 6
0
        public HttpResponseMessage DeletePaymentById([FromUri] int paymentId)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            String           Message          = validates.ValidateDelete(paymentId);

            if (Message == String.Empty)
            {
                Payment payment = new Payment();
                Boolean sucess;

                if (paymentRepository == null)
                {
                    PaymentRepository paymentRepository = new PaymentRepository();
                    payment = paymentRepository.GetPaymentById(paymentId);

                    if (payment != null)
                    {
                        sucess = paymentRepository.DeleteObject(payment, true);

                        if (sucess)
                        {
                            return(new HttpResponseMessage(HttpStatusCode.NoContent));
                        }
                        return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not delete record."));
                    }
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Register not found."));
                }
                else
                {
                    payment = paymentRepository.GetPaymentById(paymentId);
                    sucess  = paymentRepository.DeleteObject(payment, true);

                    if (sucess)
                    {
                        return(new HttpResponseMessage(HttpStatusCode.NoContent));
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Register not found."));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, Message));
        }
Exemplo n.º 7
0
        public HttpResponseMessage CreateDebt([FromBody] DebtViewModel debtAttribute)
        {
            Validates        validates        = new Validates();
            MessageViewModel messageAttribute = new MessageViewModel();
            var Message = validates.ValidateDebt(debtAttribute);

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

                if (debtRepository == null)
                {
                    DebtRepository debtRepository = new DebtRepository();
                    debt.Value       = Convert.ToDecimal(debtAttribute.Value);
                    debt.Date        = Convert.ToDateTime(debtAttribute.Date);
                    debt.Description = debtAttribute.Description;
                    FriendRepository friendName = new FriendRepository();
                    debt.FriendIdIn  = friendName.GetFriendIdByName(debtAttribute.FriendNameIn);
                    debt.FriendIdOut = friendName.GetFriendIdByName(debtAttribute.FriendNameOut);

                    sucess = debtRepository.Insert(debt);

                    if (sucess)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create()));
                    }
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not create debit."));
                }
                else
                {
                    sucess = debtRepository.Insert(debt);

                    if (sucess)
                    {
                        return(Request.CreateResponse(HttpStatusCode.Created, messageAttribute.Create()));
                    }
                }
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Could not create debit."));
            }
            return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, Message));
        }