Exemplo n.º 1
0
 public List<App> GetAllApps()
 {
     using (var db = new AdminDbContext())
     {
         return db.Apps.ToList();
     }
 }
Exemplo n.º 2
0
 public List<User> GetAllUsers()
 {
     using (var db = new AdminDbContext())
     {
         return db.Users.ToList();
     }
 }
Exemplo n.º 3
0
 public Obj GetObject(int navId, string key)
 {
     using (var db = new AdminDbContext())
     {
         return db.Objs.FirstOrDefault(o => o.NavId == navId && o.Key.ToLower() == key.ToLower());
     }
 }
Exemplo n.º 4
0
 public Nav GetNav(string navSlug)
 {
     using (var db = new AdminDbContext())
     {
         Nav nav = db.Navs.Include(n=>n.App).FirstOrDefault(e => e.Slug.ToLower() == navSlug.ToLower() && (e.Status == NavStatus.Public));
         return nav;
     }
 }
Exemplo n.º 5
0
 public List<Nav> GetAllNavs()
 {
     using (var db = new AdminDbContext())
     {
         var list = db.Navs.Include(n=>n.App).ToList();
         return db.Navs.ToList();
     }
 }
Exemplo n.º 6
0
 public User GetUser(string username, bool updateLastActivity)
 {
     using (var db = new AdminDbContext())
     {
         User user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == username.ToLower());
         if (user == null) throw new SiteException("User not found.");
         return user;
     }
 }
Exemplo n.º 7
0
        public void UpdateUser(User user)
        {
            using (var db = new AdminDbContext())
            {
                var ent = db.Users.FirstOrDefault(e => e.UserId == user.UserId);
                if (ent == null) return;

                ent.UserName = user.UserName;
                ent.DisplayName = user.DisplayName;
                ent.Email = user.Email;

                db.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public void DeleteNav(string navSlug)
        {
            using (var db = new AdminDbContext())
            {
                var nav = db.Navs.FirstOrDefault(e => e.Slug.ToLower() == navSlug.ToLower());
                if (nav == null) return;

                db.Navs.Remove(nav);
                // update app
                var app = db.Apps.FirstOrDefault(a => a.AppId == nav.AppId);
                if (app == null) throw new SiteException("App not found.");
                app.InstanceCount--;

                db.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public int AddNav(Nav nav)
        {
            using (var db = new AdminDbContext())
            {
                if (db.Navs.FirstOrDefault(n => n.Slug.ToLower() == nav.Slug.ToLower()) != null)
                    throw new SiteException(string.Format("Slug '{0}' exists already.", nav.Slug));

                db.Navs.Add(nav);

                // update app
                var app = db.Apps.FirstOrDefault(a => a.AppId == nav.AppId);
                if (app == null) throw new SiteException("App not found.");
                app.InstanceCount++;

                db.SaveChanges();

                return nav.NavId;
            }
        }
            public SimpleMembershipInitializer()
            {
                Database.SetInitializer<AdminDbContext>(null);

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

                    WebSecurity.InitializeDatabaseConnection("AdminDbContext", "Fan_User", "UserId", "UserName", autoCreateTables: false);
                }
                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);
                }
            }
Exemplo n.º 11
0
        public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl)
        {
            string provider = null;
            string providerUserId = null;

            if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId))
            {
                return RedirectToAction("Manage");
            }

            if (ModelState.IsValid)
            {
                // Insert a new user into the database
                using (AdminDbContext db = new AdminDbContext())
                {
                    User user = db.Users.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower());
                    // Check if user already exists
                    if (user == null)
                    {
                        // Insert name into the profile table
                        db.Users.Add(new User { UserName = model.UserName });
                        db.SaveChanges();

                        OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName);
                        OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false);

                        return RedirectToLocal(returnUrl);
                    }
                    else
                    {
                        ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name.");
                    }
                }
            }

            ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName;
            ViewBag.ReturnUrl = returnUrl;
            return View(model);
        }
Exemplo n.º 12
0
        public void SaveObject(int navId, string key, ObjFormat format, string data)
        {
            using (var db = new AdminDbContext())
            {
                var obj = db.Objs.FirstOrDefault(o => o.NavId == navId && o.Key.ToLower() == key.ToLower());
                if (obj != null)
                {
                    // update
                    obj.Format = format;
                    obj.Data = data;
                }
                else
                {
                    // add
                    db.Objs.Add(new Obj
                    {
                        NavId = navId,
                        Key = key,
                        Format = format,
                        Data = data,
                    });
                }

                db.SaveChanges();
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// </summary>
        /// <param name="nav"></param>
        /// <remarks>
        /// </remarks>
        /// <exception cref="Fan.SiteException">The slug trying to update to already exists.</exception>
        public void UpdateNav(Nav nav)
        {
            using (var db = new AdminDbContext())
            {
                var ent = db.Navs.FirstOrDefault(n => n.NavId == nav.NavId);
                if (ent == null) return;

                // if there is a dup slug, other than the one you are updating
                if (db.Navs.FirstOrDefault(n => n.Slug.ToLower() == nav.Slug.ToLower() && n.NavId != nav.NavId) != null)
                    throw new SiteException(string.Format("Slug '{0}' exists already.", nav.Slug));

                ent.Name = nav.Name;
                ent.Slug = nav.Slug;
                ent.Description = nav.Description;

                db.SaveChanges();
            }
        }