예제 #1
0
        public IActionResult Order(int?id)
        {
            object data;

            TempData.TryGetValue("ToastMessage", out data);
            if (data != null)
            {
                ViewBag.Toast = JsonSerializer.Deserialize <ToastAlertViewModel>(data as string);
            }
            if (id != null && id > 0)                                      //check that user has given an id and that the ID given is bigger than 0 (all ids are bigger than 0)
            {
                var Session = HttpContext.Session.GetString("PubSession"); //user must be logged in to view an order
                if (Session != null)
                {
                    PubSessions pubSession = _context.GetPubSession(Session); //get session info
                    if (pubSession != null)                                   //session exists
                    {
                        if (pubSession.UserId > 0)                            //if a user is logged in...
                        {
                            PubUsers pubUsers = _context.GetPubUser(pubSession.UserId);
                            if (pubUsers != null)
                            {
                                Get_PubOrderViewModel OrderDetails = _context.GetPubOrder((int)id);
                                if (OrderDetails != null && (OrderDetails.UserId == pubUsers.UserId || pubUsers.UserAccessRank == Models.Enum.UserAccessRank.Admin)) //only logged in user and admins are allowed to view.
                                {
                                    OrderViewModel orderViewModel = new OrderViewModel
                                    {
                                        OrderDetails = OrderDetails,
                                        OrderItems   = _context.GetPubOrderItems((int)id)
                                    };
                                    ViewBag.LoggedInUserID = pubUsers.UserId;
                                    ViewBag.UserAccessRank = pubUsers.UserAccessRank;
                                    return(View(orderViewModel));
                                }
                            }
                        }
                    }
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
예제 #2
0
 public IActionResult CancelOrder(int id)
 {
     if (id > 0)                                                    //all ids are bigger than 0
     {
         var Session = HttpContext.Session.GetString("PubSession"); //user must be logged in to view an order
         if (Session != null)
         {
             PubSessions pubSession = _context.GetPubSession(Session);           //get session info
             if (pubSession != null)                                             //session exists
             {
                 if (pubSession.UserId > 0)                                      //if a user is logged in...
                 {
                     PubUsers pubUsers = _context.GetPubUser(pubSession.UserId); //fetch logged in user....
                     if (pubUsers != null)                                       //if user exists...
                     {
                         Get_PubOrderViewModel Order = _context.GetPubOrder(id);
                         if (Order != null)
                         {
                             if (Order.UserId == pubUsers.UserId)
                             {
                                 if (_context.RemovePubOrder(id))
                                 {
                                     ViewBag.RemovedOrderID = id;
                                     return(View());
                                 }
                             }
                             TempData["ToastMessage"] = JsonSerializer.Serialize(ToastAlert.Toast("Error", "Error: Could not cancel order."));
                             return(RedirectToAction("Order", new { id }));
                         }
                     }
                 }
             }
         }
     }
     TempData["ToastMessage"] = JsonSerializer.Serialize(ToastAlert.DefaultError());
     return(RedirectToAction("Index", "Home"));
 }