Ejemplo n.º 1
0
 bool IExciteService.AddUser(String userName)
 {
     using (ExciteContext db = new ExciteContext())
     {
         UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == userName.ToLower());
         // Check if user already exists
         if (user == null)
         {
             // Insert name into the profile table
             db.UserProfiles.Add(new UserProfile { UserName = userName });
             db.SaveChanges();
             return true;
         }
         else
             return false;
     }
 }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<ExciteContext>(null);

                try
                {
                    using (var context = new ExciteContext())
                    {
                        if (!context.Database.Exists())
                        {
                            // Create the SimpleMembership database without Entity Framework migration schema
                            ((IObjectContextAdapter)context).ObjectContext.CreateDatabase();
                        }
                    }

                    WebSecurity.InitializeDatabaseConnection("ExciteConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588", ex);
                }
            }