public IActionResult PaymentOption(PaymentFirstVM model) { if (HttpContext.GetLoggedUser() != null) { TempData["logged"] = "True"; } var user = HttpContext.GetLoggedUser(); var details = con.BillingDetails.Where(x => x.UserId == user.Id).FirstOrDefault(); BillingDetails billing = new BillingDetails(); if (model.CustomerInfo != null && details != null) { details.Email = model.CustomerInfo.Email; details.Fullname = model.CustomerInfo.FullName; details.Zip = model.CustomerInfo.Zip; details.Country = model.CustomerInfo.Country; details.City = model.CustomerInfo.City; details.StreetAddress = model.CustomerInfo.StreetAddress; details.UserId = user.Id; details.PhoneNumber = model.CustomerInfo.PhoneNumber; con.SaveChanges(); } else { billing.Email = model.CustomerInfo.Email; billing.Fullname = model.CustomerInfo.FullName; billing.Zip = model.CustomerInfo.Zip; billing.Country = model.CustomerInfo.Country; billing.City = model.CustomerInfo.City; billing.StreetAddress = model.CustomerInfo.StreetAddress; billing.UserId = user.Id; billing.PhoneNumber = model.CustomerInfo.PhoneNumber; con.Add(billing); } con.SaveChanges(); int product = con.Products.Find(model.ProductId).Id; if (!ModelState.IsValid) { return(RedirectToAction("Index", "HomePage")); } PaymentOptionVM pay = new PaymentOptionVM { Price = model.Price, ProductName = model.ProductName, PaypalRoute = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&amount=" + model.Price.ToString() + "&[email protected]&item_name=" + model.ProductName + "&return=https://localhost:44342/Payment/PaymentSuccess?ProductId=" + product }; return(View(pay)); }
public IActionResult Index(int ProductId) { if (HttpContext.GetLoggedUser() == null) { return(RedirectToAction("Index", "Login")); } TempData["logged"] = "True"; Product product = con.Products.Find(ProductId); var user = HttpContext.GetLoggedUser(); BillingDetails billing = con.BillingDetails.Where(x => x.UserId == user.Id).FirstOrDefault(); ShippingInfo shipping = new ShippingInfo(); if (billing != null) { shipping.FullName = billing.Fullname; shipping.Email = billing.Email; shipping.Zip = billing.Zip; shipping.Country = billing.Country; shipping.StreetAddress = billing.StreetAddress; shipping.City = billing.City; shipping.PhoneNumber = billing.PhoneNumber; } PaymentFirstVM model = new PaymentFirstVM { ProductId = ProductId, Price = product.Price, ShortDescription = product.ShortDescription, GenderId = product.GenderId, CategoryId = product.CategoryId, ImageRoute = product.ImageRoute, ProductName = product.ProductName, CustomerInfo = shipping }; return(View(model)); }