Esempio n. 1
0
    public static void Updatecustomers(List <Customer> customers)
    {
        using (var context = new WebsiteTTKEntities())
        {
            foreach (Customer item in customers)
            {
                var userStore = new Microsoft.AspNet.Identity.EntityFramework.UserStore <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>();
                var manager   = new Microsoft.AspNet.Identity.UserManager <Microsoft.AspNet.Identity.EntityFramework.IdentityUser>(userStore);

                var user = manager.FindByIdAsync(item.AspNetUser.Id).Result;
                if (user != null)
                {
                    user.Email       = item.AspNetUser.Email;
                    user.PhoneNumber = item.AspNetUser.PhoneNumber;

                    Microsoft.AspNet.Identity.IdentityResult result = manager.UpdateAsync(user).Result;
                }
                else
                {
                    user = new Microsoft.AspNet.Identity.EntityFramework.IdentityUser()
                    {
                        UserName = item.AspNetUser.UserName, Email = item.AspNetUser.Email, PhoneNumber = item.AspNetUser.PhoneNumber
                    };

                    Microsoft.AspNet.Identity.IdentityResult result = manager.CreateAsync(user, item.Password).Result;
                }
            }
        }
    }