// GET: AdminTickets
 public ActionResult Index()
 {
     using (TicketDominatorContext context = new TicketDominatorContext()) {
         var list = context.Tickets.OrderBy(x => x.Artist).ToList();
         return(View(list));
     }
 }
        public ActionResult Checkout()
        {
            Guid UserId = UserHelper.GetUserId();

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

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                var shoppingCartItems = context.ShoppingCarts.Include("Ticket").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 {
                        Ticket        = item.Ticket,
                        PricePaidEach = item.Ticket.Price,
                        Quantity      = item.Quantity
                    };
                    newOrder.OrderDetails.Add(od);
                }
                return(View("Details", newOrder));
            }
        }
Beispiel #3
0
        public static void TransferTemporaryUserToRealUser(Guid tempId, string userId)
        {
            using (TicketDominatorContext context = new TicketDominatorContext()) {
                if (context.ShoppingCarts.Any(x => x.UserId == tempId))
                {
                    Guid newUserId = Guid.Parse(userId);
                    var  list      = context.ShoppingCarts.Include("Ticket").Where(x => x.UserId == tempId);

                    foreach (var tempCart in list)
                    {
                        var sameItemInShoppingCart = context.ShoppingCarts
                                                     .FirstOrDefault(x => x.Ticket.Id == tempCart.Ticket.Id && x.UserId == newUserId);

                        if (sameItemInShoppingCart == null)
                        {
                            tempCart.UserId = newUserId;
                        }
                        else
                        {
                            sameItemInShoppingCart.Quantity++;
                            context.ShoppingCarts.Remove(tempCart);
                        }
                    }

                    context.SaveChanges();
                }
            }
        }
 public ActionResult Partial()
 {
     using (TicketDominatorContext context = new TicketDominatorContext()) {
         ShoppingCartSummary summary = GetShoppingCartSummary(context);
         return(PartialView("_AjaxCartSummary", summary));
     }
 }
Beispiel #5
0
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(this.RedirectToAction("Index"));
            }

            Guid UserID = UserHelper.GetUserId();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

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

                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));
            }
        }
        // GET: Tickets
        public ActionResult Index(int page = 1, int pageQty = 12, string sortExp = "date", string sortOrder = "asc")
        {
            if (User.IsInRole("Admin") && !Request.IsAjaxRequest())
            {
                return(this.RedirectToAction("Index", "AdminTickets"));
            }

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                ViewBag.SortExpression = sortExp;
                ViewBag.SortOrder      = sortOrder;

                //var items = from i in context.Tickets where i.Amount > 0 select i;
                var items = context.Tickets.Where(x => x.Amount > 0);

                switch (sortExp)
                {
                case "date":
                    if (sortOrder == "desc")
                    {
                        items = items.OrderByDescending(x => x.Date);
                    }
                    else
                    {
                        items = items.OrderBy(x => x.Date);
                    }
                    break;

                case "artist":
                    if (sortOrder == "desc")
                    {
                        items = items.OrderByDescending(x => x.Artist);
                    }
                    else
                    {
                        items = items.OrderBy(x => x.Artist);
                    }
                    break;

                case "venue":
                    if (sortOrder == "desc")
                    {
                        items = items.OrderByDescending(x => x.Venue);
                    }
                    else
                    {
                        items = items.OrderBy(x => x.Venue);
                    }

                    break;
                }

                if (Request.IsAjaxRequest())
                {
                    return(Json(items.ToList(), JsonRequestBehavior.AllowGet));
                }
                return(View(items.ToPagedList(page, pageQty)));
            }
        }
        private ShoppingCartSummary GetShoppingCartSummary(TicketDominatorContext 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.Ticket.Price);
                summary.Quantity   = cartList.Sum(x => x.Quantity);
            }
            return(summary);
        }
 public ActionResult Create(Ticket obj)
 {
     try {
         // TODO: Add insert logic here
         using (TicketDominatorContext context = new TicketDominatorContext()) {
             context.Tickets.Add(obj);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     } catch {
         return(View());
     }
 }
 public ActionResult Edit(int id, Ticket obj)
 {
     try {
         using (TicketDominatorContext context = new TicketDominatorContext()) {
             var item = context.Tickets.FirstOrDefault(x => x.Id == id);
             TryUpdateModel(item);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     } catch {
         return(View());
     }
 }
 public ActionResult Delete(int id, FormCollection collection)
 {
     try {
         // TODO: Add delete logic here
         using (TicketDominatorContext context = new TicketDominatorContext()) {
             Ticket ticket = context.Tickets.FirstOrDefault(x => x.Id == id);
             context.Tickets.Remove(ticket);
             context.SaveChanges();
             return(RedirectToAction("Index"));
         }
     } catch {
         return(View());
     }
 }
        // GET: Ticket/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index"));
            }

            Ticket result = null;

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                result = context.Tickets.FirstOrDefault(x => x.Id == id);
            }
            return(View(result));
        }
        // GET: SHoppingCart
        public ActionResult Index()
        {
            using (TicketDominatorContext context = new TicketDominatorContext()) {
                ViewBag.Summary = GetShoppingCartSummary(context);

                var carts = context.ShoppingCarts.Include("Ticket").Where(x => x.UserId == UserId);

                if (Request.IsAjaxRequest())
                {
                    return(Json(carts.ToList(), JsonRequestBehavior.AllowGet));
                }

                return(View(carts.ToList()));
            }
        }
        // GET: Tickets/Details/5
        public ActionResult Details(int?id)
        {
            if (User.IsInRole("Admin"))
            {
                return(this.RedirectToAction("Index", "AdminTickets"));
            }

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

            Ticket result = null;

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                result = context.Tickets.FirstOrDefault(x => x.Id == id);
            }

            return(View(result));
        }
        public ActionResult AddToCart(int id, bool mobile = false)
        {
            using (TicketDominatorContext context = new TicketDominatorContext())
            {
                Ticket addTicket = context.Tickets.FirstOrDefault(x => x.Id == id);

                if (addTicket != null)
                {
                    var sameItemInCart = context.ShoppingCarts.FirstOrDefault(x => x.Ticket.Id == id && x.UserId == UserId);
                    if (sameItemInCart == null)
                    {
                        ShoppingCart sc = new ShoppingCart
                        {
                            Ticket    = addTicket,
                            UserId    = UserId,
                            Quantity  = 1,
                            DateAdded = DateTime.Now
                        };
                        context.ShoppingCarts.Add(sc);
                    }
                    else
                    {
                        sameItemInCart.Quantity++;
                    }

                    context.SaveChanges();
                }
                ShoppingCartSummary summary = GetShoppingCartSummary(context);

                if (mobile)
                {
                    return(Json(summary, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(PartialView("_AjaxCartSummary", summary));
                }
            }
        }
Beispiel #15
0
        // GET: Order
        public ActionResult Index()
        {
            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                var UserId = UserHelper.GetUserId();

                List <Order> orders = context.Orders.ToList();

                if (!User.IsInRole("Admin"))
                {
                    orders = context.Orders.Where(x => x.UserId == UserId).ToList();
                }

                if (Request.IsAjaxRequest())
                {
                    return(Json(orders, JsonRequestBehavior.AllowGet));
                }

                return(View(orders));
            }
        }
        public ActionResult Checkout(Order order)
        {
            Guid UserID = UserHelper.GetUserId();

            ViewBag.ApplicationUser = UserHelper.GetApplicationUser();

            using (TicketDominatorContext context = new TicketDominatorContext()) {
                var shoppingCartTickets = context.ShoppingCarts.Include("Ticket").Where(x => x.UserId == UserId);
                order.OrderDetails = new List <OrderDetail>();

                order.UserId    = UserId;
                order.OrderDate = DateTime.Now;

                foreach (var ticket in shoppingCartTickets)
                {
                    int quantity = 0;
                    int.TryParse(Request.Form.Get(ticket.Ticket.Id.ToString()), out quantity);

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

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

                return(RedirectToAction("Details", "Order", new { id = order.Id }));
            }
        }
 // GET: Ticket/Create
 public ActionResult Create()
 {
     using (TicketDominatorContext context = new TicketDominatorContext()) {
         return(View());
     }
 }