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));
        }
Esempio n. 2
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));
        }
        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));
        }
        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));
        }