Exemplo n.º 1
0
        // POST: api/Payment
        public async Task <IHttpActionResult> Post([FromBody] Payment valPayment)
        {
            string vResult = "4";

            IPaymentData vPaymentData = new PaymentData();

            try {
                bool vNullField = VerifyNullFileds(valPayment);

                if (vNullField)
                {
                    vResult = "2";
                    return(ResponseMessage(Request.CreateResponse(HttpStatusCode.NotAcceptable, new { Code = HttpStatusCode.NotAcceptable, Message = Messages.vListContainNullValue, Result = vResult })));
                }
                string vResponse = await vPaymentData.Insert(valPayment);

                if (!string.IsNullOrEmpty(vResponse))
                {
                    if (vResponse == "1")
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.Created, new { Code = HttpStatusCode.Created, Message = Messages.vOkInserted, Result = vResponse })));
                    }
                    else if (vResponse == "3")
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, new { Code = HttpStatusCode.InternalServerError, Message = Messages.vInsertPaymentError, Result = vResponse })));
                    }
                    else if (vResponse != "4")
                    {
                        return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, new { Code = HttpStatusCode.InternalServerError, Message = Messages.vPaymentGatewayError, Result = vResponse })));
                    }
                }
            } catch (Exception vEx) {
                string vMessage = vEx.Message;
                return(ResponseMessage(Request.CreateResponse(HttpStatusCode.InternalServerError, new { Code = HttpStatusCode.InternalServerError, Message = Messages.vInternalServerError, Result = vResult })));
            }
            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, new { Code = HttpStatusCode.BadRequest, Message = Messages.vNotInserted, Result = vResult })));
        }