Пример #1
0
        public ActionResult CreateUser(CreateUserViewModel model)
        {
            if (HttpContext.User.IsInRole("Gamer"))
            {
                return(HttpNotFound("Your have already a gamer type."));
            }

            _model = model;

            _model.BeerUser.ClientId = HttpContext.User.Identity.GetUserId();
            ModelState.Remove("BeerUser.ClientId");
            if (!ModelState.IsValid)
            {
                return(View("CreateUser", _model));
            }

            try
            {
                _model.ErrorMessage        = null;
                _model.GamerTypes          = _service.GetAllGamerTypes();
                _model.SelectListGamerType = GetSelectListItems(_service.GetAllGamerTypeNames());

                _service.CreateBeerUser(_model.BeerUser.ClientId, _service.GetGamerTypeByName(model.SelectedGamerType), _model.BeerUser.Pseudonym);
                UserManager.AddToRole(HttpContext.User.Identity.GetUserId(), "Gamer");
            }
            catch (BeerException e)
            {
                _model.ErrorMessage = e.Message;
                return(View("CreateUser", _model));
            }

            return(RedirectToAction("Index", "Dashboard"));
        }