Beispiel #1
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));
            }
        }
Beispiel #2
0
        public String ValidateUpdatePayment(PaymentViewModel paymentAttribute, int paymentId)
        {
            String Message = String.Empty;
            String testId  = paymentId.ToString();

            if (testId == "")
            {
                Message = "Id deve estar preenchido. /n ";
            }

            if (testId.Length <= 0)
            {
                Message = String.Concat(Message, "Id deve ser maior que 0.");
            }

            int  number;
            bool TestId = Int32.TryParse(testId, out number);

            if (!TestId)
            {
                Message = String.Concat(Message, "Campo Id deve ser inteiro /n ");
            }
            else if (Message == "")
            {
                if (paymentAttribute == null)
                {
                    Message = String.Concat(Message, "Não pode ser enviado pagamento em branco. /n ");
                }

                if (paymentAttribute.Value.Length <= 0)
                {
                    Message = String.Concat(Message, "Campo valor não pode ser nulo. /n ");
                }

                Decimal value     = 0;
                bool    TestValue = Decimal.TryParse(paymentAttribute.Value, out value);

                if (!TestValue)
                {
                    Message = String.Concat(Message, "Campo valor deve ser inteiro /n ");
                }
            }
            return(Message);
        }