Exemplo n.º 1
0
        public async Task <bool> AddNewUser(NewUserDataModel model)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                try
                {
                    await connection.OpenAsync();

                    connection.Execute("", model, commandType: CommandType.StoredProcedure);
                    return(true);
                }
                catch (SqlException)
                {
                    return(false);
                }
            }
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> CreateNewUser(NewUserDataModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadGateway, ModelState));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Passwords do not match"));
            }

            try
            {
                model.Password = _passwordService.HashUserPassword(model.Password);
                await _userManager.AddNewUser(model);

                return(Request.CreateResponse(HttpStatusCode.OK));
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Error creating new user"));
            }
        }