-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Renamed AccountsController.cs. Implemented logic of promote and demot…
…e users.
- Loading branch information
1 parent
300db8a
commit 781ec64
Showing
2 changed files
with
104 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
104 changes: 104 additions & 0 deletions
104
Eventures/Eventures.Web/Controllers/AccountsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
namespace Eventures.Web.Controllers | ||
{ | ||
using System.Collections.Generic; | ||
using AutoMapper; | ||
using Microsoft.AspNetCore.Identity; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Models; | ||
using Services.Interfaces; | ||
using ViewModels.Accounts; | ||
|
||
public class AccountsController : Controller | ||
{ | ||
private readonly IAccountsService accountsService; | ||
private readonly SignInManager<User> signInManager; | ||
private readonly UserManager<User> userManager; | ||
private readonly IMapper mapper; | ||
|
||
public AccountsController(IAccountsService accountsService, UserManager<User> userManager, SignInManager<User> signInManager, IMapper mapper) | ||
{ | ||
this.accountsService = accountsService; | ||
this.userManager = userManager; | ||
this.signInManager = signInManager; | ||
this.mapper = mapper; | ||
} | ||
|
||
public IActionResult Register() | ||
{ | ||
return this.View(); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Register(RegisterViewModel model) | ||
{ | ||
if (!this.ModelState.IsValid) | ||
{ | ||
return this.View(model); | ||
} | ||
|
||
var isRegister = this.accountsService.Register(model.Username, model.Password, model.ConfirmPassword, model.Email, | ||
model.FirstName, model.LastName, model.UniqueCitizenNumber).GetAwaiter().GetResult(); | ||
|
||
if (!isRegister) | ||
{ | ||
return this.View(); | ||
} | ||
|
||
return this.RedirectToAction("Index", "Home"); | ||
} | ||
|
||
public IActionResult Login() | ||
{ | ||
return this.View(); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult Login(LoginViewModel model) | ||
{ | ||
if (!this.ModelState.IsValid) | ||
{ | ||
return this.View(model); | ||
} | ||
|
||
var isLogin = this.accountsService.Login(model.Username, model.Password, model.RememberMe); | ||
|
||
if (!isLogin) | ||
{ | ||
return this.View(); | ||
} | ||
|
||
return this.RedirectToAction("Index", "Home"); | ||
} | ||
|
||
public IActionResult Logout() | ||
{ | ||
this.accountsService.Logout(); | ||
return this.RedirectToAction("Index", "Home"); | ||
} | ||
|
||
public IActionResult AllUsers() | ||
{ | ||
var users = this.accountsService.GetAllUsers(); | ||
var userViewModels = this.mapper.Map<List<UserViewModel>>(users); | ||
this.ViewData["Users"] = userViewModels; | ||
return this.View(); | ||
} | ||
|
||
[HttpPost] | ||
public IActionResult PromoteUser(UserIdViewModel model) | ||
{ | ||
this.accountsService.PromoteUser(model.Id); | ||
|
||
return this.RedirectToAction("AllUsers", "Accounts"); | ||
} | ||
|
||
|
||
[HttpPost] | ||
public IActionResult DemoteUser(UserIdViewModel model) | ||
{ | ||
this.accountsService.DemoteUser(model.Id); | ||
|
||
return this.RedirectToAction("AllUsers", "Accounts"); | ||
} | ||
} | ||
} |