public async Task <IActionResult> BanUser(string userId) { //check if user exist at all var userExists = await _userService.FindUserByIdAsync(userId); if (userExists == null) { ViewBag.ErrorTitle = $"You are tring to ban user that does not exist!"; return(View("Error")); } //check the role of user (if user does not have a role,but exist - return FreeUser) string roleName = await _roleManager.GetUserRoleName(userId); //check if u try to ban admin if (roleName.ToLower() == "admin") { ViewBag.ErrorTitle = $"You are tring to ban user in role administrator"; ViewBag.ErrorMessage = "Users in role \"Administrator\" cannot be banned!"; return(View("Error")); } else { var username = await _userService.FindUsernameByIdAsync(userId); var vm = new BanViewModel { UserId = userId, Username = username, }; return(View(vm)); } }
public ActionResult Index(BanViewModel model) { if (model.IsBanned == true) { var result = _customerService.BanCustomer(model.Id); if (result.Succedeed) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "Error", new ErrorViewModel { ErrorMessage = result.Message })); } } if (model.IsBanned == false) { var result = _customerService.UnbanCustomer(model.Id); if (result.Succedeed) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "Error", new ErrorViewModel { ErrorMessage = result.Message })); } } return(RedirectToAction("Index")); }
public async Task <IActionResult> BanUserConfirmation(BanViewModel vm) { //check if user exist at all var userExists = await _userService.FindUserByIdAsync(vm.UserId); if (userExists == null) { ViewBag.ErrorTitle = $"You are tring to ban user that does not exist!"; return(View("Error")); } string roleName = await _roleManager.GetUserRoleName(vm.UserId); if (roleName.ToLower() == "admin") { ViewBag.ErrorTitle = $"You are tring to ban user in role administrator"; ViewBag.ErrorMessage = "Users in role \"Administrator\" cannot be banned!"; return(View("Error")); } var banDto = await _dtoMapper.MapBanVmToDto(vm); //var user = await _userManager.FindByIdAsync(userId); var user = await _userService.BanUserAsync(banDto); this.TempData["Success"] = $"User: {user.UserName} successfully Banned"; return(RedirectToAction("ListUsers", "Admin")); }
public async Task <ActionResult> Ban(BanViewModel model) { if (ModelState.IsValid) { var banList = model.Name.Split(',', ';').Select(x => new Domain.Models.GenericReference <Domain.Models.BanType>() { Name = x.TrimSafe(), Type = model.BanType }).ToList(); var cmd = new GlobalBanCommand(banList, model.Reason).SetUserContext(User); var response = await cmd.Execute(); if (response.Success) { ViewBag.SuccessMessage = "Bans Saved"; } else { ModelState.AddModelError("", response.Message); return(View("Ban", model)); } } return(View("Ban", new BanViewModel())); }
public ActionResult Ban(string name) { var ban = new BanViewModel { Name = name }; return(View(ban)); }
public async Task <BanDto> MapBanVmToDto(BanViewModel banVm) => new BanDto { UserId = banVm.UserId, Username = banVm.Username, Description = banVm.Description, ExpirationDate = banVm.ExpirationDate, };
public ActionResult Ban(BanViewModel banViewModel) { string message = String.Format("The user was banned on the next period: {0}.", EnumHelper <BanPeriod> .GetEnumDescription(banViewModel.BanPeriod.ToString())); MessageAttention(message); return(RedirectToAction("Get", "Game")); }
public async Task BanAsync() { var dialog = await BanViewModel.CreateInstanceAsync(this.authentication, this); if (dialog != null) { await dialog.ShowDialogAsync(); } }
public static async Task <bool> BanAsync(Authentication authentication, IUserDescriptor descriptor) { var dialog = await BanViewModel.CreateInstanceAsync(authentication, descriptor); if (dialog != null && await dialog.ShowDialogAsync() == true) { return(true); } return(false); }
public IActionResult UnBan(BanViewModel vm) { try { pRepo.UpdateBan(vm.Profiel.ID, false); } catch (ArgumentOutOfRangeException) { TempData["Ongeldig"] = "ID is invalid, try again!"; } return(RedirectToAction("BannedOverzicht")); }
public async Task <IActionResult> CreateBan(Guid id, BanViewModel entity) { if (ModelState.IsValid) { await this.banService.CreateAsync(id, entity.Description, entity.Period); this.toastNotification.AddSuccessToastMessage("User successfully banned"); return(RedirectToAction("Index", "Users")); } ModelState.AddModelError(String.Empty, "Please fill in the form!"); this.toastNotification.AddWarningToastMessage("User couldn't be banned"); return(View(entity)); }
public async Task <IActionResult> CreateBan(Guid id, BanViewModel BanVM) { if (ModelState.IsValid) { await _banService.CreateBanAsync(id, BanVM.BanReason, BanVM.DurationInDays); _logger.LogInformation("User has been succesfully banned"); return(RedirectToAction("Index", "Users")); } ModelState.AddModelError(String.Empty, "Please fill in the form!"); _logger.LogInformation("User could not be banned"); return(View(BanVM)); }
public Ban(IMainWindowTelnet telnet, string playerID = "") { InitializeComponent(); var model = new BanModel(telnet); var vm = new BanViewModel(model); DataContext = vm; model.Ended += Model_Ended; model.Name = playerID; }
public IActionResult Ban(string userId) { var banTerms = Enum.GetNames(typeof(BanTerm)); var localizedTerms = banTerms.Select(term => _stringLocalizer[term]).ToArray(); var listItems = localizedTerms.Select((term, i) => new SelectListItem(term, banTerms[i])); var viewModel = new BanViewModel { UserId = userId, Terms = listItems }; return(View(viewModel)); }
public async Task <IActionResult> Edit(BanViewModel viewModel) { if (ModelState.IsValid) { var dto = _mapper.Map <BanDto>(viewModel); await _banService.EditAsync(dto, GetCurrentUserId()); return(RedirectToAction("Details", new { id = dto.Id })); } else { ViewBag.ErrorMessage = ModelState.ModelErrorsToString(); return(View(viewModel)); } }
public async Task <ActionResult> Ban([FromBody] BanViewModel model) { var ajaxReturn = new AjaxFeedbackViewModel(); try { var dto = Mapper <BanViewModel, BanDTO>(model); dto.AdminAccount = User.Identity.Name; dto.ExpiresAt = Convert.ToDateTime(model.Date, CultureInfo.CurrentCulture.DateTimeFormat); await _banService.BanAccount(dto); } catch (InvalidIdException) { // Id of an account that does not exist. ajaxReturn.Title = _localizer["Error"]; ajaxReturn.Message = _localizer["InvalidAttempt"]; return(Json(ajaxReturn)); } catch (NoAuthorizationException) { // Game Master trying to cheat LogUnauthorizedAccess(User.Identity.Name, "Admin/Account/Ban:Post"); return(RedirectToAction("List")); } catch (InvalidAdminAccountException) { // Invalid logged-in admin account. // I don't think is possible throw this error by this controller ajaxReturn.Title = _localizer["Error"]; ajaxReturn.Message = _localizer["InvalidAttempt2"]; return(Json(ajaxReturn)); } catch (RequiredAdminCharacterException) { // Need a god character or game master character to do it. ajaxReturn.Title = _localizer["Error"]; ajaxReturn.Message = _localizer["YouNeedAGodCharacter"]; return(Json(ajaxReturn)); } catch (AccountAlreadyBannedException) { // Can not ban, because the target account is already banned. ajaxReturn.Title = _localizer["Error"]; ajaxReturn.Message = _localizer["AlreadyBanned"]; return(Json(ajaxReturn)); } catch (Exception ex) { // Unknow error LogError(ex, "Error on Admin/Account/Ban"); ajaxReturn.Title = _localizer["Error"]; ajaxReturn.Message = _localizer["UnknowError"]; return(Json(ajaxReturn)); } // Success ajaxReturn.Title = _localizer["Success"]; ajaxReturn.Message = _localizer["BannedSuccefully"]; return(Json(ajaxReturn)); }
public BanViewModel Adapt(IBan ban) { var result = new BanViewModel(ban.UnbanTime, ban.PlayerName, ban.CreatorName, ban.DurationInSeconds, ban.Reason, ban.PlayerId); return(result); }
public ActionResult Ban(BanViewModel ban) { _userService.Ban(ban.Name, "", ban.Duration); return(RedirectToAction("Index", "Games", new FilterViewModel())); }
public async Task BanAsync() { var dialog = await BanViewModel.CreateInstanceAsync(this.authentication, this); dialog?.ShowDialog(); }
public static async Task <bool> BanAsync(Authentication authentication, IUserDescriptor descriptor) { var dialog = await BanViewModel.CreateInstanceAsync(authentication, descriptor); return(dialog?.ShowDialog() == true); }
public ActionResult BanPartialView(BanViewModel model) { return(PartialView("BanPartialView", model)); }
public ActionResult Ban() { var banViewModel = new BanViewModel(); return(View(banViewModel)); }