コード例 #1
0
        private Cart GetCartFromSession(IHttpSession session)
        {
            if (!session.Contains("shoppingCart"))
            {
                session.Add("shoppingCart", new Cart());
            }

            return(session.Get <Cart>("shoppingCart"));
        }
コード例 #2
0
        public IHttpResponse Index(IHttpSession session)
        {
            string user = "";

            if (session.Contains(SessionStore.CurrentUserKey))
            {
                user = session.Get(SessionStore.CurrentUserKey).ToString();
            }
            return(new ViewResponse(HttpStatusCode.Ok, new IndexView(user)));
        }
コード例 #3
0
        public IHttpResponse Greeting(IHttpRequest request)
        {
            IHttpSession session = request.Session;
            Dictionary <string, string> formData = request.FormData;

            if (session.Get("firstName") == null)
            {
                session.Add("firstName", formData["firstName"]);
            }
            else if (session.Get("lastName") == null)
            {
                session.Add("lastName", formData["lastName"]);
            }
            else if (session.Get("age") == null)
            {
                session.Add("age", formData["age"]);
            }
            return(new RedirectResponse("/greeting"));
        }
コード例 #4
0
        private int GetProductsCount(IHttpSession session)
        {
            int productsCount = 0;

            if (session.Contains("shoppingCart"))
            {
                Cart cart = session.Get <Cart>("shoppingCart");
                productsCount = cart.Cakes.Count;
            }
            return(productsCount);
        }
コード例 #5
0
        public static ShoppingCart GetShoppingCart(this IHttpSession session)
        {
            ShoppingCart shoppingCart = session.Get <ShoppingCart>(CurrentShoppingCartSessionKey);

            if (shoppingCart == null)
            {
                shoppingCart = new ShoppingCart();
                session.Add(CurrentShoppingCartSessionKey, shoppingCart);
            }

            return(shoppingCart);
        }
コード例 #6
0
        public IHttpResponse AddGame(IHttpSession session)
        {
            if (!session.IsAuthenticated())
            {
                return(new RedirectResponse("/login"));
            }

            LoginViewModel user = session.Get <LoginViewModel>(SessionStore.CurrentUserKey);

            if (!user.IsAdmin)
            {
                return(new RedirectResponse("/"));
            }

            return(this.FileViewResponse("Game/add-game"));
        }
コード例 #7
0
        public IHttpResponse Index(IHttpRequest req)
        {
            IHttpSession session = req.Session;

            if (session.IsLoggedIn())
            {
                string username = session.Get <string>(SessionStore.CurrentUserKey);

                this.SetLoggedInView();

                this.ViewData["is-logged-in-view"] = $"<h1>Welcome, <span class=\"text-warning\">{username}</span></h1><hr class=\"bg-white\" style = \"height: 2px\"/><h3>IRunes wishes you a fun experience</h3>";
            }
            else
            {
                this.SetGuestView();
            }

            return(this.FileViewResponse("Home/index"));
        }
コード例 #8
0
        public IHttpResponse AdminGames(IHttpSession session)
        {
            if (!session.IsAuthenticated())
            {
                return(new RedirectResponse("/login"));
            }

            LoginViewModel user = session.Get <LoginViewModel>(SessionStore.CurrentUserKey);

            if (!user.IsAdmin)
            {
                return(new RedirectResponse("/"));
            }

            List <GameViewModel> games = this.gameService.GetAdminGames();

            StringBuilder sb = new StringBuilder();

            foreach (GameViewModel game in games)
            {
                sb.Append(@"<tr class=""table-warning"">" +
                          $@"<th scope=""row"">{game.SequelNumber}</th>" +
                          $"<td>{game.Title}</td>" +
                          $" <td>{game.Size:f1} GB</td>" +
                          $"<td>{game.Price:f1} &euro;</td>" +
                          " <td>" +
                          $@"<a href=""/edit-game/{game.Id}"" class=""btn btn-warning btn-sm"">Edit</a>" +
                          $@"<a href=""/delete-game/{game.Id}"" class=""btn btn-danger btn-sm"">Delete</a>" +
                          "</td>" +
                          "</tr>");
            }

            string result = sb.ToString();

            this.ViewData["show-games"] = "block";
            this.ViewData["games"]      = result;

            return(this.FileViewResponse("Game/admin-games"));
        }
コード例 #9
0
        public IHttpResponse DeleteGame(IHttpSession session, string urlParameter)
        {
            if (!session.IsAuthenticated() || !session.Get <LoginViewModel>(SessionStore.CurrentUserKey).IsAdmin)
            {
                return(new RedirectResponse("/"));
            }

            int id = int.Parse(urlParameter);

            GameToAddOrEditViewModel game = this.gameService.GetById(id);

            this.ViewData["id"]          = game.Id.ToString();
            this.ViewData["title"]       = game.Title;
            this.ViewData["description"] = game.Description;
            this.ViewData["thumbnail"]   = game.ThumbnailUrl != null ? game.ThumbnailUrl : string.Empty;
            this.ViewData["trailer"]     = game.Trailer;
            this.ViewData["price"]       = game.Price.ToString("f2");
            this.ViewData["size"]        = game.Size.ToString("f1");
            this.ViewData["date"]        = game.ReleaseDate.ToString("yyyy-MM-dd");

            return(this.FileViewResponse("Game/delete-game"));
        }