Example #1
0
        public async Task <ActionResult> OnPost(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                ModelState.AddModelError("", "Uploaded file is empty or null.");
                return(Page());
            }

            var isImage = file.IsImage();

            if (!isImage)
            {
                ModelState.AddModelError("", "This photo extension is not allowed!");
                return(Page());
            }

            if (!ModelState.IsValid)
            {
                return(Redirect("/Identity/Account/Manage"));
            }

            if (file.Length > 0)
            {
                await _questionCommands.UploadImage(file);

                StatusMessage = "Your profile picture has been uploaded successfully";
            }
            return(Redirect("/Identity/Account/Manage"));
        }