Exemplo n.º 1
0
 // GET: CigarAdmin
 public ActionResult Index(int page = 1, int pageQty = 25)
 {
     using (HotAshContext context = new HotAshContext()) {
         var cigars = context.Cigars;
         return(View(cigars.ToPagedList(page, pageQty)));
     }
 }
Exemplo n.º 2
0
        public ActionResult Checkout()
        {
            Guid UserID = UserHelper.GetUserID();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();
            ViewBag.CheckingOut     = true;

            using (HotAshContext context = new HotAshContext()) {
                var shoppingCartItems = context.ShoppingCarts.Include("Cigar").Where(x => x.UserID == UserID);

                Order newOrder = new Order {
                    OrderDate    = DateTime.Now,
                    UserID       = UserID,
                    OrderDetails = new List <OrderDetail>()
                };

                foreach (var item in shoppingCartItems)
                {
                    OrderDetail od = new OrderDetail {
                        Cigar         = item.Cigar,
                        PricePaidEach = item.Cigar.Price,
                        Quantity      = item.Quantity
                    };
                    newOrder.OrderDetails.Add(od);
                }
                return(View("Details", newOrder));
            }
        }
Exemplo n.º 3
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(this.RedirectToAction("Index"));
            }

            Guid UserID = UserHelper.GetUserID();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

            using (HotAshContext context = new HotAshContext()) {
                IQueryable <Order> orders = context.Orders.Include(p => p.OrderDetails.Select(c => c.Cigar));

                Order order;

                if (User.IsInRole("Admin"))
                {
                    order = orders.FirstOrDefault(x => x.ID == id);
                }
                else
                {
                    order = orders.FirstOrDefault(x => x.ID == id && x.UserID == UserID);
                }

                if (order == null)
                {
                    return(this.RedirectToAction("Index"));
                }

                return(View(order));
            }
        }
Exemplo n.º 4
0
        public static void TransferTemporaryUserToRealUser(Guid tempId, string userId)
        {
            using (HotAshContext context = new HotAshContext()) {
                if (context.ShoppingCarts.Any(x => x.UserID == tempId))
                {
                    Guid newUserID = Guid.Parse(userId);
                    var  list      = context.ShoppingCarts.Include("Cigar").Where(x => x.UserID == tempId);

                    foreach (var tempCart in list)
                    {
                        var sameItemInCart = context.ShoppingCarts
                                             .FirstOrDefault(x => x.Cigar.ID == tempCart.Cigar.ID && x.UserID == newUserID);

                        if (sameItemInCart == null)
                        {
                            tempCart.UserID = newUserID;
                        }
                        else
                        {
                            sameItemInCart.Quantity++;
                            context.ShoppingCarts.Remove(tempCart);
                        }
                    }

                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 5
0
 public ActionResult Partial()
 {
     using (HotAshContext context = new HotAshContext()) {
         ShoppingCartSummary summary = GetShoppingCartSummary(context);
         return(PartialView("_AjaxCartSummary", summary));
     }
 }
Exemplo n.º 6
0
        public ActionResult AddToCart(int id)
        {
            using (HotAshContext context = new HotAshContext()) {
                Cigar addCigar = context.Cigars.FirstOrDefault(x => x.ID == id);

                if (addCigar != null)
                {
                    var sameItemInCart = context.ShoppingCarts.FirstOrDefault(x => x.Cigar.ID == id && x.UserID == UserID);
                    if (sameItemInCart == null)
                    {
                        ShoppingCart sc = new ShoppingCart {
                            Cigar     = addCigar,
                            UserID    = UserID,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        sameItemInCart.Quantity++;
                    }

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);
                return(PartialView("_AjaxCartSummary", summary));
            }
        }
Exemplo n.º 7
0
        // GET: SHoppingCart
        public ActionResult Index()
        {
            using (HotAshContext context = new HotAshContext()) {
                ViewBag.Summary = GetShoppingCartSummary(context);

                var carts = context.ShoppingCarts.Include("Cigar").Where(x => x.UserID == UserID);
                return(View(carts.ToList()));
            }
        }
Exemplo n.º 8
0
        public ActionResult Edit(int id, Cigar obj)
        {
            using (HotAshContext context = new HotAshContext()) {
                var cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                TryUpdateModel(cigar);
                context.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 9
0
 public ActionResult Create(Cigar obj)
 {
     try {
         using (HotAshContext context = new HotAshContext()) {
             context.Cigars.Add(obj);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     } catch {
         return(View());
     }
 }
Exemplo n.º 10
0
        private ShoppingCartSummary GetShoppingCartSummary(HotAshContext context)
        {
            ShoppingCartSummary summary = new ShoppingCartSummary();
            var cartList = context.ShoppingCarts.Where(x => x.UserID == UserID);

            if (cartList != null && cartList.Count() > 0)
            {
                summary.TotalValue = cartList.Sum(x => x.Quantity * x.Cigar.Price);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
Exemplo n.º 11
0
        // GET: Cigars
        public ActionResult Index(int page = 1, int pageQty = 15)
        {
            if (User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "CigarAdmin"));
            }

            using (HotAshContext context = new HotAshContext()) {
                var cigars = context.Cigars.OrderBy(x => x.Name);
                return(View(cigars.ToPagedList(page, pageQty)));
            }
        }
Exemplo n.º 12
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try {
                using (HotAshContext context = new HotAshContext()) {
                    Cigar cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                    context.Cigars.Remove(cigar);
                    context.SaveChanges();

                    return(RedirectToAction("Index"));
                }
            } catch {
                return(View());
            }
        }
Exemplo n.º 13
0
        // GET: CigarAdmin/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            Cigar result = null;

            using (HotAshContext context = new HotAshContext()) {
                result = context.Cigars.FirstOrDefault(x => x.ID == id);
            }
            return(View(result));
        }
Exemplo n.º 14
0
        public ActionResult Index(int page = 1, int pageSize = 15)
        {
            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

            using (HotAshContext context = new HotAshContext()) {
                var UserId = UserHelper.GetUserID();
                IPagedList <Order> orders = context.Orders.ToPagedList(page, pageSize);

                if (!User.IsInRole("Admin"))
                {
                    orders = context.Orders.Where(x => x.UserID == UserId).ToPagedList(page, pageSize);
                }

                return(View(orders));
            }
        }
Exemplo n.º 15
0
        // GET: Cigars/Details/5
        public ActionResult Details(int?id)
        {
            if (User.IsInRole("Admin"))
            {
                return(RedirectToAction("Index", "CigarAdmin"));
            }

            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            using (HotAshContext context = new HotAshContext()) {
                Cigar cigar = context.Cigars.FirstOrDefault(x => x.ID == id);
                return(View(cigar));
            }
        }
Exemplo n.º 16
0
        public ActionResult Checkout(Order order)
        {
            Guid UserID = UserHelper.GetUserID();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

            using (HotAshContext context = new HotAshContext()) {
                var shoppingCartCigars = context.ShoppingCarts.Include("Cigar").Where(x => x.UserID == UserID);
                order.OrderDetails = new List <OrderDetail>();

                order.UserID    = UserID;
                order.OrderDate = DateTime.Now;

                foreach (var Cigar in shoppingCartCigars)
                {
                    int quantity = 0;
                    int.TryParse(Request.Form.Get(Cigar.Cigar.ID.ToString()), out quantity);

                    if (quantity > 0)
                    {
                        OrderDetail od = new OrderDetail {
                            Cigar         = Cigar.Cigar,
                            PricePaidEach = Cigar.Cigar.Price,
                            Quantity      = quantity
                        };
                        order.OrderDetails.Add(od);
                    }
                }

                order = context.Orders.Add(order);
                context.ShoppingCarts.RemoveRange(shoppingCartCigars);
                context.SaveChanges();

                return(RedirectToAction("Details", "Orders", new { id = order.ID }));
            }
        }