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); } }
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; } }
// // GET: /Order/ public ActionResult Index(int?page) { logger.Info("Index Method Start" + " at " + DateTime.UtcNow); try { int userId = Convert.ToInt32(System.Web.Security.Membership.GetUser().ProviderUserKey); logger.Info("Index Method User " + userId + " at " + DateTime.UtcNow); UserProfile userProfile = db.UserProfiles.Where(u => u.UserProfileId == userId).FirstOrDefault(); ViewBag.UserProfileData = userProfile; var thisRole = Roles.GetRolesForUser(System.Web.Security.Membership.GetUser().UserName).FirstOrDefault(); var coupon = new Coupon(); int coupAmt; List <OrderCoupon> orderCoupons = new List <OrderCoupon>(); orderCoupons = (List <OrderCoupon>)Session["_ssnOrderCoupon"]; if (orderCoupons != null) { foreach (var orderCoupon in orderCoupons) { coupon = db.Coupons.Where(c => c.CouponId == orderCoupon.CouponId).FirstOrDefault(); coupon.CouponsUsed++; coupon.AvailableCoupons = coupon.TotalCoupons - coupon.CouponsUsed; db.Entry(coupon).State = EntityState.Modified; db.SaveChanges(); db.OrderCoupons.Add(orderCoupon); db.SaveChanges(); } //foreach (var orderCoupon in orderCoupons) //{ // coupon = db.Coupons.Where(c => c.CouponId == orderCoupon.CouponId).FirstOrDefault(); // coupon.CouponsUsed++; // coupon.AvailableCoupons -= coupon.CouponsUsed; // db.Entry(coupon).State = EntityState.Modified; // db.SaveChanges(); //} } //DateTime dayBefore = DateTime.Now.AddDays(-10); //var updateOrders = db.Orders.Where(x => (x.Status == 3 || x.Status == 4) && x.UserProfileId == userId && x.OrderDate > dayBefore); var updateOrders = db.Orders.Include(o => o.UserProfile).Include(y => y.ProviderService).Where(x => x.UserProfileId == userId && (x.Status == 7)); if (userId != null) { var thisUser = (from u in db.UserProfiles where u.UserProfileId == userId select u).FirstOrDefault(); if (thisUser.IsSkip == "No") { List <UserPreferenceViewModel> thisUserPreference = (from pref in db.Preferences join so in db.ServiceOperators on pref.ServiceOperatorId equals so.ServiceOperatorId join st in db.ServiceTypes on pref.ServiceTypeId equals st.ServiceTypeId where pref.UserProfileId == thisUser.UserProfileId select new UserPreferenceViewModel { RechargeNumber = pref.RechargeNumber, Amount = pref.Amount, ServiceTypeName = st.ServiceTypeName, ServiceTypeId = st.ServiceTypeId, OperatorName = so.OperatorName }).ToList(); ViewBag.UserPreference = thisUserPreference; //query = (from user in db.AspNetUsers // join userRoles in db.AspNetUserRoles on user.Id equals userRoles.UserId into rolesOfUser // from rou in rolesOfUser.DefaultIfEmpty() // join roles in db.AspNetRoles on rou.RoleId equals roles.Id into getRoles // from gr in getRoles.DefaultIfEmpty() // join userInfo in db.UserInfoes on user.UserInfo_Id equals userInfo.Id into users // from u in users.DefaultIfEmpty() // select new UserRoleViewModel // { // Role = (gr.Name == null) ? "User" : gr.Name, // UserName = (u.UserName == null) ? "None" : u.UserName, // Name = (u.UserName == null) ? "None" : u.Name, // EmailId = (u.EmailId == null) ? "None" : u.EmailId, // UserId = (u.Id == null) ? 0 : u.Id, // RoleId = (gr.Id == null) ? "None" : gr.Id // }).OrderBy(o => o.UserName).ToList(); //List<Preference> preferenceData = (from preference in db.Preferences // where preference.UserProfileId == userId // select preference).ToList(); //ViewBag.preferenceData = preferenceData; } } logger.Info("Index Method Orders " + updateOrders.Count() + " at " + DateTime.UtcNow); if (updateOrders.Count() > 0) { foreach (var order in updateOrders) { if (!string.IsNullOrEmpty(order.Remarks)) { ServiceEngine.ServiceHelper serviceHelper = new ServiceEngine.ServiceHelper(); string[] paramString = order.Remarks.Split(','); string transactionNumber = string.Empty; if (paramString.Count() > 1) { transactionNumber = paramString[1]; } else { transactionNumber = paramString[0]; } db.Entry(order).State = EntityState.Modified; int serviceTypeId = 1; if (order.ProviderService.ServiceTypeId == 1) { serviceTypeId = 1; } else if (order.ProviderService.ServiceTypeId == 2) { serviceTypeId = 4; } else if (order.ProviderService.ServiceTypeId == 3) { serviceTypeId = 2; } else if (order.ProviderService.ServiceTypeId == 4) { serviceTypeId = 3; } string result = serviceHelper.GetTransactionResult(transactionNumber, serviceTypeId); ProcessResult(result, order); } } db.SaveChanges(); } int pagenumber = page ?? 1; var orders = (thisRole == "Admin") ? db.Orders.Include(o => o.UserProfile).Include(o => o.ProviderService).OrderByDescending(x => x.OrderDate) : db.Orders.Include(o => o.UserProfile).Include(o => o.ProviderService).Where(x => x.UserProfileId == userId).OrderByDescending(x => x.OrderDate); //if (thisRole == "Admin") //{ // var orders = db.Orders.Include(o => o.UserProfile).Include(o => o.ProviderService).OrderByDescending(x => x.OrderDate); //} //else { // var orders = db.Orders.Include(o => o.UserProfile).Include(o => o.ProviderService).Where(x => x.UserProfileId == userId).OrderByDescending(x => x.OrderDate); //} logger.Info("Index Method End" + " at " + DateTime.UtcNow); return(View(orders.ToPagedList(pagenumber, 10))); } catch (Exception ex) { throw ex; } }