Пример #1
0
        public ICollection <SongModel> RandomSongs(int num)
        {
            ICollection <SongModel> ret = new List <SongModel>();
            int randomToName            = random.Next(2000);

            for (int i = 0; i < num; i++)
            {
                SongModel temp = new SongModel();
                temp.SongImagePath = SongImages.ElementAt(random.Next(0, SongImages.Count));
                int addToName = randomToName + i;
                temp.SongName    = "song" + addToName.ToString();
                temp.SongPath    = RandomString(12);
                temp.ReleaseDate = new DateTime(2018, 3, 11);
                if (i % 9 == 0)
                {
                    temp.Genre = enum_Genre.Jazz.ToString();
                }
                else if (i % 3 == 0)
                {
                    temp.Genre = enum_Genre.Blues.ToString();
                }
                else if (i % 5 == 0)
                {
                    temp.Genre = enum_Genre.Classic.ToString();
                }
                else if (i % 7 == 0)
                {
                    temp.Genre = enum_Genre.Electronic.ToString();
                }
                else if (i % 11 == 0)
                {
                    temp.Genre = enum_Genre.Rock.ToString();
                }
                else if (i % 13 == 0)
                {
                    temp.Genre = enum_Genre.Country.ToString();
                }
                else if (i % 17 == 0)
                {
                    temp.Genre = enum_Genre.Pop.ToString();
                }
                else if (i % 19 == 0)
                {
                    temp.Genre = enum_Genre.Hip_hop.ToString();
                }
                else
                {
                    temp.Genre = enum_Genre.Folk.ToString();
                }
                temp.AddedDate = DateTime.Today;
                ret.Add(temp);
                dbContext.Add(temp);
            }

            dbContext.SaveChanges();
            return(ret);
        }
        public async Task <IActionResult> Create([Bind("PlaylistId,Public,PlaylistName")] PlaylistModel playlistModel, IFormFile playlistImage)
        {
            playlistModel.PlaylistImage = FileHelper.SaveFile(playlistImage, "images", playlistImage.FileName);
            if (ModelState.IsValid)
            {
                _context.Add(playlistModel);
                //adds the crated playlist too the current user lit of playlists
                int       id   = HttpContext.Session.GetInt32(SessionConsts.UserId).Value;
                UserModel user = await _context.Users.SingleOrDefaultAsync(m => m.UserId == id);

                user.SavedPlaylists.Add(playlistModel);

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(playlistModel));
        }
Пример #3
0
        public async Task <IActionResult> Create([Bind("SongId,SongName,Genre,ReleaseDate")] SongModel songModel, IFormFile songImagePath, IFormFile songPath)
        {
            if (ModelState.IsValid)
            {
                songModel.SongPath      = FileHelper.SaveFile(songPath, "songs", songPath.FileName);
                songModel.AddedDate     = DateTime.UtcNow;
                songModel.SongImagePath = FileHelper.SaveFile(songImagePath, "images", songImagePath.FileName);
                _context.Add(songModel);
                //adds the created song to the current artist according to the session
                int id = HttpContext.Session.GetInt32(SessionConsts.UserId).Value;
                Models.BridgeModel.ArtistSongModel temp = new Models.BridgeModel.ArtistSongModel();
                temp.SongId = songModel.SongId;
                temp.UserId = id;
                _context.Add(temp);

                await _context.SaveChangesAsync();

                FacebookModel facebookModel = new FacebookModel();
                await facebookModel.Post(string.Format("A new song has been added to the site -> {0}", songModel.SongName));

                return(RedirectToAction(nameof(Display)));
            }
            return(View(songModel));
        }
Пример #4
0
        public async Task <IActionResult> Create([Bind("UserId,Username,FirstName,LastName,Email,Password")] UserModel userModel)
        {
            string error = CheckIfExists(userModel.Username, userModel.Email);

            if (error != "")
            {
                ViewData["Error"] = error;
                return(View());
            }
            if (ModelState.IsValid)
            {
                userModel.TimeOfLastLogin    = DateTime.UtcNow;
                userModel.DateOfRegistration = DateTime.UtcNow;
                _context.Add(userModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("SignIn", "UserModels"));
            }
            return(View(userModel));
        }
Пример #5
0
        public async Task <IActionResult> Create([Bind("ArtistName,FirstName,LastName,UserId,Username,Email,Password")] ArtistModel artistModel, IFormFile artistImageFile)
        {
            var checkIfExistsUserName = await _context.Users.SingleOrDefaultAsync(u => u.Username == artistModel.Username);

            var checkIfExistsEmail = await _context.Users.SingleOrDefaultAsync(u => u.Email == artistModel.Email);

            string error = "";

            if (checkIfExistsUserName != null)
            {
                error = "Username is already taken.";
            }

            else if (checkIfExistsEmail != null)
            {
                error = "Email is already taken.";
            }
            ViewData["Error"] = error;
            if (error != "")
            {
                return(View());
            }


            if (ModelState.IsValid)
            {
                artistModel.TimeOfLastLogin    = DateTime.UtcNow;
                artistModel.DateOfRegistration = DateTime.UtcNow;
                artistModel.ArtistImage        = FileHelper.SaveFile(artistImageFile, "images", artistImageFile.FileName);
                _context.Add(artistModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "SongModels"));
            }
            return(View(artistModel));
        }