コード例 #1
0
        public async Task <bool> Register(RegisterViewModel account, string role)
        {
            BaseAccount ba     = account.ConvertToBaseAccount();
            var         result = await userManager.CreateAsync(ba, ba.Password);

            if (result.Succeeded)
            {
                if (role == "Customer")
                {
                    using (var connection = new SqlConnection(_connectionString))
                    {
                        connection.Open();
                        SqlCommand sqlCommand = new SqlCommand("dbo.UpdateCustomerData", connection);
                        sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
                        sqlCommand.Parameters.AddWithValue("@address", account.Address);
                        sqlCommand.Parameters.AddWithValue("@zipcode", account.Zipcode);
                        sqlCommand.Parameters.AddWithValue("@town", account.Town);
                        sqlCommand.Parameters.AddWithValue("@firstname", account.FirstName);
                        sqlCommand.Parameters.AddWithValue("@lastname", account.LastName);
                        sqlCommand.Parameters.AddWithValue("@username", account.Username);
                        int retAffectedRows = sqlCommand.ExecuteNonQuery();
                        if (retAffectedRows == -1)
                        {
                            return(false);
                        }
                        connection.Close();
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }