Example #1
0
        public IHttpResponse All(IHttpSession session)
        {
            if (!session.IsLoggedIn())
            {
                return(new RedirectResponse("/"));
            }

            this.SetLoggedInView();

            List <Album> albums = this.albumService.GetAll();

            if (albums.Count == 0)
            {
                this.ViewData["all-albums"] = "There are currently no albums.";

                return(this.FileViewResponse("/Albums/all"));
            }

            StringBuilder sb = new StringBuilder();

            foreach (Album album in albums)
            {
                sb.Append($"<li><a href =\"/Albums/details?albumId={album.Id}\">{album.Name}</a></li>");
            }

            this.ViewData["all-albums"] = sb.ToString();

            return(this.FileViewResponse("/Albums/all"));
        }
        public IHttpResponse Logout(IHttpSession session)
        {
            if (session.IsLoggedIn())
            {
                session.Clear();
            }


            return(new RedirectResponse("/"));
        }
        public IHttpResponse Register(IHttpSession session)
        {
            this.SetGuestView();

            if (session.IsLoggedIn())
            {
                this.InsertErrorMessage(AppConstants.FirstLogout);
                return(this.FileViewResponse("/Home/index"));
            }

            return(this.FileViewResponse("/Users/register"));
        }
Example #4
0
        public IHttpResponse Create(IHttpSession session)
        {
            if (!session.IsLoggedIn())
            {
                this.InsertErrorMessage(AppConstants.NotLoggedIn);

                return(this.FileViewResponse("Home/index"));
            }

            this.SetLoggedInView();

            return(this.FileViewResponse("/Albums/Create"));
        }
        public IHttpResponse Login(IHttpSession session)
        {
            if (session.IsLoggedIn())
            {
                this.InsertErrorMessage(AppConstants.AlreadyLogged);

                this.SetLoggedInView();

                return(this.FileViewResponse("Home/index"));
            }

            this.SetGuestView();

            return(this.FileViewResponse("/Users/login"));
        }
        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"));
        }
Example #7
0
        public IHttpResponse Details(IHttpSession session, string id)
        {
            if (!session.IsLoggedIn())
            {
                return(new RedirectResponse("/"));
            }

            AlbumDetailsView album = this.albumService.GetById(id);

            if (album == null)
            {
                return(new RedirectResponse("/"));
            }

            List <Track> tracks = this.albumService.GetAllTracks(album.Id);

            StringBuilder sb = new StringBuilder();

            if (tracks.Count == 0)
            {
                sb.Append("No tracks");
            }
            else
            {
                for (int i = 0; i < tracks.Count; i++)
                {
                    Track track = tracks[i];

                    sb.Append($"<li>{i+1}. <a href= \"/Tracks/details?albumId={album.Id}&trackId={track.Id}\">{track.Name}</a></li>");
                }
            }

            this.ViewData["cover"]       = album.Cover;
            this.ViewData["albumId"]     = album.Id;
            this.ViewData["album-price"] = $"${ album.Price.ToString("f2")}";
            this.ViewData["album-name"]  = album.Name;
            this.ViewData["all-tracks"]  = sb.ToString();

            this.SetLoggedInView();

            return(this.FileViewResponse("/Albums/details"));
        }