Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 2
0
        public IActionResult ChangePicture(List <IFormFile> uploadedFiles)
        {
            var    user        = _userManager.FindByIdAsync(CurrentLoggedUserId.ToString()).Result;
            string imageS3Name = null;

            if (uploadedFiles.Count == 0)
            {
                ModelState.AddModelError("Picture", "Please choose a picture!");
                return(View("MyAccount", user));
            }
            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("MyAccount", user));
            }
            if (formFile.Length > MBoxConstants.MaximumImageSizeAllowed)
            {
                //Error Message
                ModelState.AddModelError("Picture", "Maximum 3MB picture size allowed!");
                return(View("MyAccount", user));
            }

            imageS3Name = _s3Manager.UploadFile(formFile);

            user.Picture = imageS3Name;
            _userManager.UpdateAsync(user).Wait();
            return(RedirectToAction("MyAccount"));
        }