public async Task <IActionResult> OnPostAddAsync() { var _files = HttpContext.Request.Form.Files; var _file = (_files.Count > 0)?_files[0]:null; if (_file == null) { ModelState.AddModelError("_form.picture", "Please cloose a picture file"); return(await OnGetAsync()); } if (!_upload.IsFileValid(_file)) { ModelState.AddModelError("_form.picture", _upload.errorMessage); } if (!ModelState.IsValid) { return(await OnGetAsync()); } AppUser _originalUser = await _db.UserTable.FirstOrDefaultAsync(m => m.Id == _manager.GetUserId(User)); if (_originalUser.picture != null) { _upload.DeleteFile(_originalUser.picture); } _originalUser.picture = _upload.UploadFile(_file); await Change(_originalUser); return(RedirectToPage("./profile", new { id = _originalUser.Id })); }