Пример #1
0
        public ApiController(SpookifyContext context)
        {
            _context = context;

            if (_context.Artists.Count() == 0)
            {
                _context.Artists.Add(new Artist {
                    ArtistName = "Artist1"
                });
                _context.SaveChanges();
            }
        }
Пример #2
0
        public IActionResult CreateUser(string Email, string ConfirmEmail, string Password, string Username, DateTime DoB, string Gender)
        {
            RegUser reguser = new RegUser {
                Email        = Email,
                ConfirmEmail = ConfirmEmail,
                Password     = Password,
                Username     = Username,
                DoB          = DoB,
                Gender       = Gender,
            };
            var res = TryValidateModel(reguser);

            System.Console.WriteLine(res);
            User test  = _context.Users.SingleOrDefault(u => u.Email == reguser.Email);
            User test2 = _context.Users.SingleOrDefault(u => u.Username == reguser.Username);

            if (test != null)
            {
                ModelState.AddModelError(string.Empty, "This email is already registered!");
            }
            if (test2 != null)
            {
                ModelState.AddModelError(string.Empty, "This Username is registered. Please try another Username!");
            }
            if (ModelState.IsValid)
            {
                User newuser = new User()
                {
                    Username  = reguser.Username,
                    Email     = reguser.Email,
                    DoB       = reguser.DoB,
                    Password  = reguser.Password,
                    Gender    = reguser.Gender,
                    CreatedAt = DateTime.Now,
                    UpdatedAt = DateTime.Now
                };
                _context.Add(newuser);
                _context.SaveChanges();
                User user = _context.Users.SingleOrDefault(u => u.Email == reguser.Email);
                HttpContext.Session.SetInt32("ActiveId", user.UserId);
                return(RedirectToAction("Webplayer", "Webplayer"));
            }

            return(View("Register"));
        }
Пример #3
0
        // public IActionResult CreatePlaylist (string PlaylistName, string PlaylistDescription, string PlaylistImage)
        // {
        public IActionResult CreatePlaylist(string playlistName, string playlistDescription, string playlistImage)
        {
            Console.WriteLine("------'CREATE PLAYLIST' METHOD STARTED-----");



            #region DUMMY DATA
            var playlists = new Playlist[]
            {
                new Playlist
                {
                    PlaylistName  = playlistName,
                    PlaylistImage = playlistDescription, PlaylistDescription = playlistImage
                },
            };
            // var playlists = new Playlist[]
            // {
            //     new Playlist{PlaylistName="Indie Jams", PlaylistImage="Indie Jams IMAGE", PlaylistDescription="Indie Jams DESCRIPTION" },

            //     new Playlist{PlaylistName="Rap", PlaylistImage="Rap IMAGE", PlaylistDescription="Rap DESCRIPTION" },

            //     new Playlist{PlaylistName="Emo", PlaylistImage="Emo IMAGE", PlaylistDescription="Emo DESCRIPTION" },
            // };

            foreach (Playlist p in playlists)
            {
                _context.Playlists.Add(p);
            }

            _context.SaveChanges();



            var tracks = new Track[]
            {
                new Track {
                    TrackName = "Karma Police", ArtistName = "Radiohead"
                },
                new Track {
                    TrackName = "Let Down", ArtistName = "Radiohead"
                },
                new Track {
                    TrackName = "Stairway to Heaven", ArtistName = "Led Zeppelin"
                },
                new Track {
                    TrackName = "Black Dog", ArtistName = "Led Zeppelin"
                },
            };

            foreach (Track t in tracks)
            {
                _context.Tracks.Add(t);
            }

            _context.SaveChanges();
            #endregion DUMMY DATA


            // #region OLD CODE
            // Playlist newPlaylist = new Playlist ()
            // {
            //     PlaylistName = PlaylistName,
            //     PlaylistDescription = PlaylistDescription,
            //     PlaylistImage = PlaylistImage,
            //     // Tracks = new List<Track>(),
            //     UserId = 1
            // };

            // newPlaylist.Dig();

            // newPlaylist.Intro("new playlist");
            // newPlaylist.PlaylistName.Intro("playlist name");
            // newPlaylist.PlaylistDescription.Intro("playlist description");
            // // newPlaylist.PlaylistImage.Intro("playlist image");

            // _context.Add(newPlaylist);
            // _context.SaveChanges();
            // #endregion OLD CODE

            Console.WriteLine("------'CREATE PLAYLIST' METHOD COMPLETED-----");


            return(View("WorkingIndex"));
        }