示例#1
0
        public JsonResult AddUser(SiteUser model)
        {
            var user = new ApplicationUser { UserName = model.UserName, Email = model.Email, LoginName = model.Name, PhoneNumber = model.Phone };
            //string password = System.Web.Security.Membership.GeneratePassword(8, 0);

            UserManager<IdentityUser> userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>());
            var result = userManager.Create(user, model.Password);

            return Json(new { success = result.Succeeded, userId = user.Id });
        }
示例#2
0
        public static List<SiteUser> GetUsers(string userId = null)
        {
            List<SiteUser> users = new List<SiteUser>();

            using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[CONNECTION_STRING].ConnectionString))
            {
                using (SqlCommand cmd = new SqlCommand("GetUsers", conn))
                {
                    if(!string.IsNullOrEmpty(userId))
                        cmd.Parameters.Add(new SqlParameter("@Id", userId));

                    cmd.CommandType = CommandType.StoredProcedure;
                    conn.Open();

                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            SiteUser user = new SiteUser();
                            user.Id = reader.GetString(0);
                            user.Email = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                            user.Phone = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
                            user.Name = reader.GetString(3);
                            user.UserName = reader.GetString(4);
                            user.RecordId = reader.GetInt32(5);
                            users.Add(user);
                        }
                    }

                    conn.Close();
                }
            }

            return users;
        }