public IActionResult UploadProfilePicture(UserProfileViewModel userProfileViewModel) { if (!ModelState.IsValid) { return(View("MyProfile", userProfileViewModel)); } using var stream = userProfileViewModel.Image.OpenReadStream(); bool checkMagicNumberOwnImpl = _fileUploadHelper.IsExtensionAllowed( CheckExtensionMethodEnum.MagicNumberOwnImplementation, stream, userProfileViewModel.Image.FileName ); bool checkFilename = _fileUploadHelper.IsExtensionAllowed( CheckExtensionMethodEnum.ExtensionFromFileName, stream, userProfileViewModel.Image.FileName ); bool checkNuget = _fileUploadHelper.IsExtensionAllowed( CheckExtensionMethodEnum.FileTypeCheckerNuget, stream, userProfileViewModel.Image.FileName ); if (!checkFilename) { return(BadRequest("File not supported")); } var imageName = userProfileViewModel.Image.FileName; var username = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; _userBll.AddProfilePictureName(username, imageName); _fileUploadHelper.SaveImage(stream, $"{_webHostEnvironment.WebRootPath}/{GeneralConstants.UploadsRelativePath}/{imageName}"); return(RedirectToAction(Names.UsersControllerMyProfile)); }