Пример #1
0
        public IActionResult Success(int Id)
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            OrderSuccessViewModel detail = new OrderSuccessViewModel();

            detail.Order = _context.Order.Find(Id);

            detail.OrderDetail = _context.OrdersDetail.Where(p => p.OrderId == Id).ToList();
            detail.Account     = _context.Account.Find(userId);

            detail.Address = _context.Address.FirstOrDefault(p => p.UserId == userId);

            return(View(detail));
        }
        public IActionResult Index()
        {
            var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            ViewBag.Messages = _context.Message.Where(p => p.CustomerId == userId && p.SenderCustomer == false && p.Status == false).Count();

            OrderSuccessViewModel userDetail = new OrderSuccessViewModel();

            userDetail.Account = _context.Account.Find(userId);

            var addresses = _context.Address.Where(p => p.UserId == userId).ToList();

            foreach (var address in addresses)
            {
                userDetail.Address = address;
            }
            return(View(userDetail));
        }
Пример #3
0
        public async Task <ActionResult> OrderConfirmationPage(Guid orderId)
        {
            var userId = await _cookieHandler.GetClaimFromAuthenticationCookieAsync("UserId");

            var userResult = await _clientService.SendRequestToGatewayAsync(ApiGateways.ApiGateway.GET_USER + userId, HttpMethod.Get);

            var user = await _clientService.ReadResponseAsync <User>(userResult.Content);

            var orderResult = await _clientService.SendRequestToGatewayAsync(ApiGateways.ApiGateway.ORDERS_GATEWAY_BASEURL + orderId, HttpMethod.Get);

            var order = await _clientService.ReadResponseAsync <Order>(orderResult.Content);

            OrderSuccessViewModel Model = new OrderSuccessViewModel
            {
                Order = order,
                User  = user
            };

            return(View(Model));
        }
 public ActionResult OrderUser(string promo, int cartId)
 {
     try
     {
         Buyer b = new Account(User.Identity.GetUserId()).Buyer;
         Cart  c = new Cart(cartId);
         Order o;
         if (promo == null || promo == "")
         {
             o           = new Order(c, DateTime.Now);
             c.IsCurrent = false;
         }
         else
         {
             PromoCode p = new PromoCode(promo);
             if (p.IsUsed(b.GetAccount()))
             {
                 return(RedirectToAction("Index", new { promoValidation = true }));
             }
             o           = new Order(c, DateTime.Now, p);
             c.IsCurrent = false;
         }
         OrderSuccessViewModel osvm = new OrderSuccessViewModel()
         {
             BuyersName      = b.Name,
             DeliveryCharges = decimal.Round(b.City.DeliverCharges).ToString(),
             DiscountAvailed = o.Promo.Discount + "%",
             OrderId         = o.OrderId.ToString(),
             Status          = o.Status,
             TotalPrice      = decimal.Round(o.TotalPrice).ToString()
         };
         return(View("OrderSuccess", osvm));
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Cart", "OrderUser");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
 public ActionResult OrderSunglasses(OrderSunglassesViewModel model, string urlRedirect = null)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         Buyer buyer;
         if (Request.IsAuthenticated)
         {
             buyer = new Account(User.Identity.GetUserId()).Buyer;
         }
         else if (Request.Cookies["anonBuyer"] != null)
         {
             buyer = new Buyer(Convert.ToInt32(Request.Cookies["anonBuyer"].Value));
             Response.Cookies.Remove("anonBuyer");
         }
         else
         {
             //return View which says that buyer's Session is timedout
             return(View("TimedOut"));
         }
         int productId = Convert.ToInt32(model.Id);
         if (buyer.GetCurrentCart() != null)
         {
             Cart       c = buyer.GetCurrentCart();
             Sunglasses s = new Sunglasses(productId);
             c.AddSunglasses(s, model.Quantity);
             s.Quantity -= model.Quantity;
             if (urlRedirect != null)
             {
                 return(Redirect(urlRedirect));
             }
             else
             {
                 return(RedirectToAction("Index", "Home"));
             }
         }
         else
         {
             Cart       c = new Cart(buyer);
             Sunglasses s = new Sunglasses(productId);
             c.AddSunglasses(s, model.Quantity);
             s.Quantity -= model.Quantity;
             if (urlRedirect != null)
             {
                 return(Redirect(urlRedirect));
             }
             else if (Request.IsAuthenticated)
             {
                 return(RedirectToAction("Index", "Home"));
             }
             Order order = new Order(c, DateTime.Now);
             OrderSuccessViewModel osvm = new OrderSuccessViewModel()
             {
                 BuyersName      = buyer.Name,
                 DeliveryCharges = decimal.Round(buyer.City.DeliverCharges).ToString(),
                 DiscountAvailed = order.Promo.Discount + "%",
                 OrderId         = order.OrderId.ToString(),
                 Status          = order.Status,
                 TotalPrice      = decimal.Round(order.TotalPrice).ToString()
             };
             return(View("OrderSuccess", osvm));
         }
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Cart", "OrderSunglasses");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }
 public ActionResult OrderPrescriptionGlasses(OrderPrescriptionGlassesViewModel model, string urlRedirect = null)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(View(model));
         }
         Buyer buyer;
         if (Request.IsAuthenticated)
         {
             buyer = new Account(User.Identity.GetUserId()).Buyer;
         }
         else if (Request.Cookies["anonBuyer"] != null)
         {
             buyer = new Buyer(Convert.ToInt32(Request.Cookies["anonBuyer"].Value));
             Response.Cookies.Remove("anonBuyer");
         }
         else
         {
             //return View which says that buyer's Session is timedout
             return(View("TimedOut"));
         }
         string fileName  = Guid.NewGuid() + Path.GetFileName(model.Prescription.FileName);
         int    productId = Convert.ToInt32(model.Id);
         if (buyer.GetCurrentCart() != null)
         {
             Cart c = buyer.GetCurrentCart();
             PrescriptionGlasses p = new PrescriptionGlasses(productId);
             c.AddPrescriptionglasses(p, model.Quantity, fileName, model.Lens);
             string path = Server.MapPath(ConfigurationManager.AppSettings["PrescriptionsPath"] + fileName);
             model.Prescription.SaveAs(path);
             p.Quantity -= model.Quantity;
             if (urlRedirect == null)
             {
                 return(RedirectToAction("Index", "Home"));
             }
             else
             {
                 return(Redirect(urlRedirect));
             }
         }
         else
         {
             Cart c = new Cart(buyer);
             PrescriptionGlasses p = new PrescriptionGlasses(productId);
             c.AddPrescriptionglasses(p, model.Quantity, fileName, model.Lens);
             var    url  = Server.MapPath(ConfigurationManager.AppSettings["PrescriptionsPath"]);
             string path = url + fileName;
             model.Prescription.SaveAs(path);
             p.Quantity -= model.Quantity;
             if (urlRedirect != null && Request.IsAuthenticated)
             {
                 return(Redirect(urlRedirect));
             }
             else if (Request.IsAuthenticated)
             {
                 return(RedirectToAction("Index", "Home"));
             }
             Order order = new Order(c, DateTime.Now);
             OrderSuccessViewModel osvm = new OrderSuccessViewModel()
             {
                 BuyersName      = buyer.Name,
                 DeliveryCharges = decimal.Round(buyer.City.DeliverCharges).ToString(),
                 DiscountAvailed = order.Promo.Discount + "%",
                 OrderId         = order.OrderId.ToString(),
                 Status          = order.Status,
                 TotalPrice      = decimal.Round(order.TotalPrice).ToString()
             };
             return(View("OrderSuccess", osvm));
         }
     }
     catch (Exception ex)
     {
         HandleErrorInfo error = new HandleErrorInfo(ex, "Cart", "OrderPrescriptionGlasses");
         return(RedirectToAction("Index", "Error", new { model = error }));
     }
 }