Ejemplo n.º 1
0
        private static void AddUser(UsersContext db, string name)
        {
            var admins = db.Groups.Where(x => x.GroupName == "Admins").ToList();

            if (admins.Count == 0)
            {
                db.Groups.Add(new Group()
                {
                    GroupName = "Admins"
                });
                db.SaveChanges();
                admins = db.Groups.Where(x => x.GroupName == "Admins").ToList();
            }

            User user = new User()
            {
                UserName = name,
                GroupId = admins[0].GroupId
            };

            db.Users.Add(user);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        private static void DeleteGroupsAndUsers(UsersContext db)
        {
            var toDelete = from us in db.Users
                           select us;
            foreach (var item in toDelete)
            {
                db.Users.Remove(item);
            }

            var groupsToDelete = from gr in db.Groups
                                 select gr;
            foreach (var item in groupsToDelete)
            {
                db.Groups.Remove(item);
            }

            db.SaveChanges();
        }