public IActionResult AddNewSong(AddNewSongViewModel model, List <IFormFile> uploadedFiles)
        {
            string imageS3Name = null;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (uploadedFiles.Count > 0)
            {
                var formFile = uploadedFiles[0];
                if (!(formFile.ContentType.Equals("image/png") || formFile.ContentType.Equals("image/jpeg") || formFile.ContentType.Equals("image/jpeg")))
                {
                    ModelState.AddModelError("Picture", formFile.ContentType + " extension is not allowed. You can only upload jpg, jpeg or png.");
                    return(View(model));
                }
                if (formFile.Length > MBoxConstants.MaximumImageSizeAllowed)
                {
                    ModelState.AddModelError("Picture", "Upload file exceeded the maximum file size limit of 3MB.");
                    return(View(model));
                }
                imageS3Name = _s3Manager.UploadFile(formFile);
            }

            var ytLink = model.YoutubeLink;

            if (ytLink.ToLower().StartsWith("www") || ytLink.ToLower().StartsWith("y"))
            {
                ytLink = "https://" + ytLink;
            }

            var vimeoLink = model.VimeoLink;

            if (vimeoLink.ToLower().StartsWith("www") || vimeoLink.ToLower().StartsWith("v"))
            {
                vimeoLink = "https://" + vimeoLink;
            }

            _songManager.Create(new Song()
            {
                Name        = model.SongName,
                AlbumName   = model.AlbumName,
                Genre       = model.Genres.ToString(),
                VimeoLink   = vimeoLink,
                YouTubeLink = ytLink,
                ReleaseDate = model.ReleaseDate,
                Lyrics      = model.SongLyrics,
                Picture     = imageS3Name,
                ArtistId    = CurrentLoggedUserId
            }, CurrentLoggedUserId);

            _songManager.Save();

            return(View("SuccessfullyPublishedSong"));
        }
        public IActionResult EditSongGenre(AddNewSongViewModel songGenre, int Id)
        {
            var song  = _songManager.GetOne(x => x.Id == Id && x.ArtistId == CurrentLoggedUserId);
            var model = FillSongDetails(Id);

            song.Genre = songGenre.Genres.ToString();
            _songManager.Update(song, CurrentLoggedUserId);
            _songManager.Save();

            return(RedirectToAction("EditSongDetails", new { song.Id }));
        }
        public AddNewSongViewModel FillSongDetails(int Id)
        {
            var song = _songManager.GetOne(x => x.Id == Id && x.ArtistId == CurrentLoggedUserId);

            var model = new AddNewSongViewModel()
            {
                SongId      = song.Id,
                AlbumName   = song.AlbumName,
                GenreName   = song.Genre,
                ReleaseDate = song.ReleaseDate,
                SongLyrics  = song.Lyrics,
                SongName    = song.Name,
                VimeoLink   = song.VimeoLink,
                YoutubeLink = song.YouTubeLink,
                Picture     = song.PictureName,
            };

            return(model);
        }
Example #4
0
 public AddSongPage()
 {
     InitializeComponent();
     BindingContext = new AddNewSongViewModel(this.Navigation);
 }