示例#1
0
        public async Task <IHttpActionResult> AddUser(NewUserBindingModel model)
        {
            RegisterBindingModel modelParam = null;

            string[] roles = null;
            if (model != null)
            {
                modelParam = (RegisterBindingModel)model;
                roles      = model.Roles;
                return(await CreateUser(modelParam, roles));
            }
            else
            {
                ModelState.AddModelError("model", "Данные для добавления пользователя отсутствуют");
                return(BadRequest(ModelState));
            }
        }
示例#2
0
        public NewUserAPIModel CreateNewUser(NewUserBindingModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("RegisterViewModel can not be null.");
            }
            if (string.IsNullOrWhiteSpace(model.Email) || string.IsNullOrWhiteSpace(model.Password))
            {
                throw new ArgumentException("Email and Password can not be null/empty.");
            }
            var exists = _repo.Where(x => x.Email == model.Email).Any();

            if (exists)
            {
                throw new EmailDuplicateException("User with such email already exists.");
            }
            var newUser = _mapper.Map <UserDb>(model);

            _repo.Add(newUser);
            _repo.SaveChanges();
            return(_mapper.Map <NewUserAPIModel>(newUser));
        }
示例#3
0
        internal async Task <bool> RegisterAsync(string username, string email, string password, string confirmPassword)
        {
            var client = new HttpClient();

            var model = new NewUserBindingModel()
            {
                Email           = email,
                Username        = username,
                Password        = password,
                ConfirmPassword = confirmPassword
            };

            var json = JsonConvert.SerializeObject(model);

            HttpContent content = new StringContent(json);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var response =
                await client.PostAsync("https://asestudyhelper.azurewebsites.net/api/Account/Register", content);

            return(response.IsSuccessStatusCode);
        }
示例#4
0
        public IActionResult AddNewUser(NewUserBindingModel model)
        {
            var newUser = _adminService.CreateNewUser(model);

            return(Ok(newUser));
        }