Exemple #1
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));
        }