Esempio n. 1
0
        internal int SavePaymentDetails(StripePaymentModel objReq)
        {

            using (var db = new WizzDataContext())
            {

                try
                {
                  //  return 1;
                    if (db.tblPaymentDetails.Any(x => x.sessionId == Convert.ToInt64(objReq.sessionId) && x.isSuccess == true && x.studentId == Convert.ToInt64(objReq.userId)))
                    {

                        return 2;
                    }
                    else
                    {
                        var sessionData = db.tblSessions.Where(x => x.pkSessionId == Convert.ToInt64(objReq.sessionId)).FirstOrDefault();
                  tblPaymentDetail paymentData = new tblPaymentDetail();
                        paymentData.studentId = Convert.ToInt64(objReq.userId);
                        paymentData.sessionId = Convert.ToInt64(objReq.sessionId);
                        paymentData.tutorId = Convert.ToInt64(sessionData.tutorId);
                        paymentData.transactionId = objReq.transactionId;
                        paymentData.isSuccess = true;
                        paymentData.createdDate = DateTime.UtcNow;
                        paymentData.paymentType = Convert.ToInt16(objReq.paymentType);
                        db.tblPaymentDetails.InsertOnSubmit(paymentData);
                     //   var requestData = db.tblSessions.Where(x => x.hasPaid == false && x.uniqueRequestId == objReq.uniqueRequestId).FirstOrDefault();
                        //if (requestData == null)
                        //    return 2;
                        //requestData.hasPaid = true;

                        db.SubmitChanges();
                        return 1;
                    }
                }
                catch (TimeoutException e)
                {
                    return 3;

                }
                catch (Exception e)
                {
                    return 0;

                }

            }

        }
        public Response<string> SavePaymentDetails(StripePaymentModel objReq)
        {
            Response<string> response = new Response<string>();
            List<string> objResp = new List<string>();
            try
            {
                StripeMethods obj = new StripeMethods();
                if (CheckRequestIsvalidornot(this.Request))
                {
                    if (ModelState.IsValid)
                    {
                        if (obj.SavePaymentDetails(objReq) == 1)
                            response.Create(true, "Payment details saved successfully", Messages.AppVersion, objResp);
                        else if (obj.SavePaymentDetails(objReq) == 3)
                            response.Create(true, "Sorry Request time is expired", Messages.AppVersion, objResp);
                        else if (obj.SavePaymentDetails(objReq) == 2)
                            response.Create(true, "Already Paid", Messages.AppVersion, objResp);
                        else
                            response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);
                    }
                    else
                        response.Create(false, ModelState.Values.FirstOrDefault().Errors.FirstOrDefault().ErrorMessage, Messages.AppVersion, objResp);
                }
                else
                    response.Create(false, Messages.FormatMessage(Messages.InvalidReq), Messages.AppVersion, objResp);

            }
            catch (Exception ex)
            {
                object session = new JavaScriptSerializer().Serialize(objReq);
                LogManager.Error("Error occured while Processing Webservice request :{0}", ex, session, ex.Message);
                response.Create(false, Messages.FormatMessage(Messages.ErrorOccure), Messages.AppVersion, objResp);
            }
            return response;
        }