コード例 #1
0
        public int DoRecharge(string orderId)
        {
            logger.Info("DoRecharge Method Start" + " at " + DateTime.UtcNow);
            try
            {
                ServiceEngine.ServiceHelper serviceHelper = new ServiceEngine.ServiceHelper();

                ServiceEngine.ServiceOrder serviceOrder = (ServiceEngine.ServiceOrder)Session["serviceOrder"];
                Order order = db.Orders.Find(Convert.ToInt32(orderId));
                db.Entry(order).State = EntityState.Modified;
                string resultString = serviceHelper.DoRecharge(serviceOrder);
                ProcessResult(resultString, order);
                db.SaveChanges();
                logger.Info("DoRecharge Method End" + " at " + DateTime.UtcNow);
                return((int)order.Status);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
コード例 #2
0
        public ActionResult Pay(string paymentMode, List <string> categoryList)
        {
            logger.Info("Pay Method Start" + " at " + DateTime.UtcNow);
            Utils              utils = new Utils();
            OrderCoupon        orderCoupon;
            List <OrderCoupon> orderCoupons = new List <OrderCoupon>();
            List <Merchant>    merchants    = new List <Merchant>();

            try
            {
                string subject = "";
                string body    = "";
                //var paymentMode = Request.Form["payment"];
                Order oldOrder = (Order)Session["order"];

                ServiceEngine.ServiceOrder serviceOrder = (ServiceEngine.ServiceOrder)Session["serviceOrder"];
                Order order             = db.Orders.Include("UserProfile").First(t => t.OrderId == oldOrder.OrderId);
                int   orderId           = order.OrderId;
                int   couponTotalAmount = 0;

                //if (categoryList != null)
                //{
                //    string[] array = categoryList.ToArray();
                //    string category = array[0].ToString();
                //    int[] categoryId = (category.Split(',').Select(int.Parse).ToArray());
                //    string coupCode = "";


                //    subject = "Coupons";
                //    for (int i = 0; i < categoryId.Length; i++)
                //    {
                //        orderCoupon = new OrderCoupon();
                //        var id = categoryId[i];
                //        var couponAmount = (from li in db.Coupons
                //                            where li.CouponId == id
                //                            select li).FirstOrDefault();
                //        couponTotalAmount += Convert.ToInt32(couponAmount.CouponValue);
                //        orderCoupon.OrderId = orderId;
                //        orderCoupon.CouponId = categoryId[i];
                //        orderCoupon.CouponAmount = couponAmount.CouponValue;

                //        orderCoupons.Add(orderCoupon);
                //        coupCode = couponAmount.CouponCode;
                //        var merchant = db.Merchants.Where(m => m.MerchantId == couponAmount.MerchantId).FirstOrDefault();

                //        body = "<div><div>Dear {0},</div><p><span>Your coupon has been sold having Couponcode - " + coupCode + " in Amount Rs." + orderCoupon.CouponAmount + " </span></p><p>Thank you.";
                //       utils.mailUser(subject, body, merchant.EmailId, merchant.MerchantName);
                //       // merchants.Add(merchant);
                //        //db.OrderCoupons.Add(orderCoupon);
                //        //db.SaveChanges();
                //    }
                //    //send mail to all the merchants whose coupon(s) have been sold.
                //    //subject = "Coupons";
                //    //body = "<div><div>Dear {0},</div><p><span>Your coupon has been sold having Couponcode = "+coupCode+" in Amount Rs."+orderCoupon.CouponAmount+" </span></p><p>Thank you.";
                //    //foreach (var merchant in merchants)
                //    //{

                //    //}
                //    Session["_ssnOrderCoupon"] = orderCoupons;
                //    order.CouponAmount = couponTotalAmount;
                //}
                //if (couponTotalAmount != null)
                //order.TotalAmount = (order.Amount) + couponTotalAmount;
                //else
                //order.TotalAmount = order.Amount;
                ////if(finalOrder.CouponAmount != null)
                ////order.CouponAmount = finalOrder.CouponAmount;
                ////if (finalOrder.TotalAmount != null)
                ////order.TotalAmount = finalOrder.TotalAmount;

                //string userName = User.Identity.Name;
                //var email = (from userProfile in db.UserProfiles
                //             where userProfile.UserName == userName
                //             select userProfile.Email).FirstOrDefault();
                //subject = "Email confirmation";
                //body = "<div><div>Dear {0},</div><p><span>Your Recharge has been successfuly done</span></p><p>Thank you for choosing us as your recharge service provider.";
                order.TotalAmount = order.Amount;
                logger.Info("Pay Method Order Id" + order.OrderId + " at " + DateTime.UtcNow);
                logger.Info("Pay Method Order Amount" + order.Amount + " at " + DateTime.UtcNow);
                ServiceEngine.ServiceHelper serviceHelper = new ServiceEngine.ServiceHelper();
                MembershipUser membershipUser             = System.Web.Security.Membership.GetUser();
                order.UserProfileId = Convert.ToInt32(membershipUser.ProviderUserKey);
                if (paymentMode == "Wallet")
                {
                    logger.Info("Pay Method Payment mode is wallet" + " at " + DateTime.UtcNow);
                    UserWallet userwallet = db.UserWallets.FirstOrDefault(x => x.UserProfileId == order.UserProfileId);
                    if (userwallet != null)
                    {
                        logger.Info("Pay Method Wallet is not null - Balance " + userwallet.Balance + " at " + DateTime.UtcNow);

                        if (userwallet.Balance > order.TotalAmount)
                        {
                            logger.Info("Pay Method Payment mode is wallet Balance" + userwallet.Balance + " and order amount " + order.TotalAmount + " at " + DateTime.UtcNow);
                            userwallet.Balance        -= Convert.ToDecimal(order.TotalAmount);
                            db.Entry(userwallet).State = EntityState.Modified;
                            db.Entry(order).State      = EntityState.Modified;
                            order.Status = (int)OrderStatus.PaymentSuceess;
                            logger.Info("Pay Method Order Status " + order.Status + " at " + DateTime.UtcNow);
                            string resultString = serviceHelper.DoRecharge(serviceOrder);
                            ProcessResult(resultString, order);
                            db.SaveChanges();
                        }
                        else
                        {
                            logger.Info("Pay Method Payment mode is wallet Balance" + userwallet.Balance + " and order amount " + order.TotalAmount + " at " + DateTime.UtcNow);
                            db.Entry(order).State = EntityState.Modified;
                            order.Status          = (int)OrderStatus.InSufficientBalance;
                            logger.Info("Pay Method Order Status " + order.Status + " at " + DateTime.UtcNow);
                            db.SaveChanges();
                            logger.Info("Pay Method End" + " at " + DateTime.UtcNow);
                            return(Redirect("~/Order/Balance"));
                        }
                    }
                    else
                    {
                        logger.Info("Pay Method Wallet is null - Balance " + userwallet.Balance + " at " + DateTime.UtcNow);
                        db.Entry(order).State = EntityState.Modified;
                        order.Status          = (int)OrderStatus.InSufficientBalance;
                        logger.Info("Pay Method Order Status " + order.Status + " at " + DateTime.UtcNow);
                        db.SaveChanges();
                        logger.Info("Pay Method End" + " at " + DateTime.UtcNow);
                        return(Redirect("~/Order/Balance"));
                    }
                    //db.Orders.Add(order);
                    //db.SaveChanges();
                    //order.Remarks = "AZ" + order.OrderId.ToString() + GetUniqueKey();
                    //serviceOrder.OrderNumber = order.Remarks;

                    Session.Remove("order");
                    Session.Remove("serviceOrder");
                    logger.Info("Pay Method End" + " at " + DateTime.UtcNow);

                    //Call Email Method
                    //utils.mailUser(subject, body, email, userName);
                    //return RedirectToAction("Index","Order");
                    return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
                    //}
                    //else
                    //{
                    //    Session.Remove("order");
                    //    Session.Remove("serviceOrder");
                    //    return RedirectToAction("Index");
                    //}
                }
                else
                {
                    logger.Info("Pay Method Payment mode is Online Payment" + " at " + DateTime.UtcNow);
                    //db.Entry(order).State = EntityState.Modified;
                    //order.Status = (int)OrderStatus.PaymentInProgress;
                    //db.SaveChanges();
                    GenerateRequest(order);
                    logger.Info("Pay Method End" + " at " + DateTime.UtcNow);

                    //Call Email Method
                    // utils.mailUser(subject, body, email, userName);
                    return(Redirect("/"));
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException e)
            {
                var outputLines = new List <string>();
                foreach (var eve in e.EntityValidationErrors)
                {
                    outputLines.Add(string.Format(
                                        "{0}: Entity of type \"{1}\" in state \"{2}\" has the following validation errors:",
                                        DateTime.Now, eve.Entry.Entity.GetType().Name, eve.Entry.State));
                    foreach (var ve in eve.ValidationErrors)
                    {
                        outputLines.Add(string.Format(
                                            "- Property: \"{0}\", Error: \"{1}\"",
                                            ve.PropertyName, ve.ErrorMessage));
                    }
                }
                System.IO.File.AppendAllLines(@"c:\temp\errors.txt", outputLines);
                logger.Error("Error: " + e.InnerException + " " + e.StackTrace + " " + e.Message + " at " + DateTime.UtcNow);
                throw;
            }
        }