aboutsummaryrefslogtreecommitdiff
path: root/ExamTemplate/Web/Controllers
diff options
context:
space:
mode:
authorSyndamia <kamen.d.mladenov@protonmail.com>2021-05-07 15:27:34 +0300
committerSyndamia <kamen.d.mladenov@protonmail.com>2021-05-07 15:27:34 +0300
commit5f2abdf275c3765290ee7d6728842cba6d3af184 (patch)
treec9393ac6375db139f2d8388fc03ed1c9bfe2405b /ExamTemplate/Web/Controllers
parent7470da2719a404b344fec4d6b2fefd92f4ce22a5 (diff)
downloadit-kariera-exam-template-5f2abdf275c3765290ee7d6728842cba6d3af184.tar
it-kariera-exam-template-5f2abdf275c3765290ee7d6728842cba6d3af184.tar.gz
it-kariera-exam-template-5f2abdf275c3765290ee7d6728842cba6d3af184.zip
Implemented editing user
Diffstat (limited to 'ExamTemplate/Web/Controllers')
-rw-r--r--ExamTemplate/Web/Controllers/UserController.cs38
1 files changed, 36 insertions, 2 deletions
diff --git a/ExamTemplate/Web/Controllers/UserController.cs b/ExamTemplate/Web/Controllers/UserController.cs
index 4a9cf31..2e5978b 100644
--- a/ExamTemplate/Web/Controllers/UserController.cs
+++ b/ExamTemplate/Web/Controllers/UserController.cs
@@ -81,13 +81,47 @@ namespace ExamTemplate.Web.Controllers
UserServiceModel userServiceModel = await this._userService.GetUserByUsernameAsync(username);
if (userServiceModel == default(UserServiceModel))
- {
return RedirectToAction("Login");
- }
UserViewModel userViewModel = this._autoMapper.Map<UserViewModel>(userServiceModel);
return View(userViewModel);
}
+
+ [HttpGet]
+ [Route("/EditProfile")]
+ public async Task<IActionResult> EditProfile()
+ {
+ UserServiceModel userServiceModel = await this._userService.GetUserByClaimsAsync(this.HttpContext.User);
+
+ if (userServiceModel == default(UserServiceModel))
+ return RedirectToAction("Login");
+
+ EditUserViewModel editUserViewModel = this._autoMapper.Map<EditUserViewModel>(userServiceModel);
+
+ return View(editUserViewModel);
+ }
+
+ [HttpPost]
+ [Route("/EditProfile")]
+ public async Task<IActionResult> EditProfile(EditUserViewModel editUserViewModel)
+ {
+ if (!this._userService.IsSignedIn(HttpContext.User))
+ return RedirectToAction("Login");
+
+ EditUserServiceModel editUserServiceModel = this._autoMapper.Map<EditUserServiceModel>(editUserViewModel);
+ bool result = await this._userService.EditUserAsync(HttpContext.User, editUserServiceModel);
+
+ if (result)
+ {
+ await this._userService.LogoutAsync();
+ return RedirectToAction("Profile", new { username = editUserViewModel.Username });
+ }
+ else
+ {
+ UserServiceModel userServiceModel = await this._userService.GetUserByClaimsAsync(HttpContext.User);
+ return RedirectToAction("Profile", new { username = userServiceModel.Username });
+ }
+ }
}
}