public async Task <IActionResult> Details()
        {
            ViewBag.Tab = Tabs.Other;
            //ViewBag.Tab = Tabs.Other;
            var cookie = Request.Cookies["orderID"];



            if (cookie != null)
            {
                if (!int.TryParse(Request.Cookies["orderId"], out int orderId))
                {
                    Response.Cookies.Delete("orderId");
                    return(RedirectToAction("Error", "Home"));
                }
                var order = await _orderService.GetAsync(orderId);

                if (order != null)
                {
                    var orderViewModel = new OrderWithDetailsViewModel
                    {
                        Order     = order,
                        EventList = await _eventService.ListAsync()
                    };
                    return(View(orderViewModel));
                }
                Response.Cookies.Delete("orderId");
            }
            // ViewBag.OrderId = orderId;
            return(View());
        }
        public async Task <IActionResult> OrderPreview(int id)
        {
            var user = await UserManager.GetUserAsync(User);

            var order = await _orderService.GetPreviewAsync(id);

            if (order == null)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
            if (!order.Accepted)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
            if (user == null)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }
            if (!await UserManager.IsInRoleAsync(user, "Admin"))
            {
                if (user.Id != order.OrderUser.UserId)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
            }
            var model = new OrderWithDetailsViewModel
            {
                Order     = order,
                EventList = await _eventService.ListAsync()
            };

            return(View(model));
        }
        public async Task <IActionResult> Details(Event model)
        {
            // ViewData["Title"] = Tabs.Other;
            OrderWithDetailsViewModel orderViewModel;
            var cookie = Request.Cookies["orderID"];

            if (cookie == null)
            {
                var order = new Order
                {
                    OrderDetails = new List <OrderDetails>()
                };
                OrderDetails orderDetails = new OrderDetails
                {
                    Price    = model.Price,
                    Quantity = model.Quantity,
                    EventID  = model.Id,
                    //EventTitle = model.Title,
                    Camera = false,
                };
                //order.EventList = await _eventService.ListAsync();
                orderViewModel = new OrderWithDetailsViewModel
                {
                    Order     = order,
                    EventList = await _eventService.ListAsync()
                };
                order.OrderDetails.Add(orderDetails);
                await _orderService.CreateAsync(order);

                Response.Cookies.Append("orderId", $"{order.Id}");
            }
            else
            {
                if (!int.TryParse(Request.Cookies["orderId"], out int orderId))
                {
                    Response.Cookies.Delete("orderId");
                    return(RedirectToAction("Error", "Home"));
                }
                var order = await _orderService.GetAsync(orderId);

                // var details = order.OrderDetails.SingleOrDefault();
                if (order == null)
                {
                    Response.Cookies.Delete("orderId");
                    return(RedirectToAction("Details"));
                }
                if (!order.OrderDetails.Any(d => d.EventID == model.Id))
                {
                    order.OrderDetails.Add(new OrderDetails
                    {
                        Price       = model.Price,
                        CameraPrice = model.CameraPrice,
                        Quantity    = model.Quantity,
                        EventID     = model.Id,
                        //EventTitle = model.Title,
                        Camera = false,
                    });
                }
                else
                {
                    var orderDetails = order.OrderDetails.Single(d => d.EventID == model.Id);
                    orderDetails.Quantity += model.Quantity;
                }
                await _orderService.UpdateAsync(order);

                orderViewModel = new OrderWithDetailsViewModel
                {
                    Order     = order,
                    EventList = await _eventService.ListAsync()
                };
            }
            //ViewData["Title"] = Tabs.Other;
            ViewBag.Tab     = Tabs.Other;
            ViewBag.OrderId = cookie;
            return(View(orderViewModel));
        }