Esempio n. 1
0
        public async Task <ActionResult> Unban([FromBody] UnbanViewModel model)
        {
            var ajaxReturn = new AjaxFeedbackViewModel();

            try
            {
                var dto = Mapper <UnbanViewModel, UnbanDTO>(model);
                dto.AccountWhoRequested = User.Identity.Name;

                await _banService.UnbanAccount(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/Unban:Post");
                return(RedirectToAction("List"));
            }
            catch (AccountIsNotBannedException)
            {
                // Trying to unban a unbanned account
                ajaxReturn.Title   = _localizer["Error"];
                ajaxReturn.Message = _localizer["AccountIsAlreadyUnbanned"];

                return(Json(ajaxReturn));
            }
            catch (Exception ex)
            {
                // Unknow error
                LogError(ex, "Error on Admin/Account/Unban");

                ajaxReturn.Title   = _localizer["Error"];
                ajaxReturn.Message = _localizer["UnknowError"];
                return(Json(ajaxReturn));
            }

            // Success
            ajaxReturn.Title   = _localizer["Success"];
            ajaxReturn.Message = _localizer["UnbannedSuccefully"];
            return(Json(ajaxReturn));
        }