Exemplo n.º 1
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new FinalProjectContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <FinalProjectContext> >()))
            {
                // Look for any students.
                if (context.Student.Any())
                {
                    return;   // DB has been seeded
                }

                context.Student.AddRange(
                    new Student
                {
                    Name      = "Example",
                    EventPref = "100M Dash",
                    Grade     = 12,
                    Phone     = "(719)555-5555"
                }
                    );
                context.SaveChanges();

                if (context.Student.Any())
                {
                    return;   // DB has been seeded.
                }



                // Look for any students.
                if (context.Results.Any())
                {
                    return;   // DB has been seeded
                }

                context.Results.AddRange(
                    new Result
                {
                    MeetName = "Example",
                    Athlete  = "John Doe",
                    Event    = "Long Jump",
                    Mark     = "20'1"
                }
                    );
                context.SaveChanges();

                if (context.Results.Any())
                {
                    return;   // DB has been seeded.
                }
            }
        }
        public void PopulateAssignedCategoryData(FinalProjectContext context,
                                                 Game game)
        {
            var allCategories  = context.Category;
            var gameCategories = new HashSet <int>(
                game.GameCategories.Select(c => c.GameID));

            AssignedCategoryDataList = new List <AssignedCategoryData>();
            foreach (var cat in allCategories)
            {
                AssignedCategoryDataList.Add(new AssignedCategoryData
                {
                    CategoryID = cat.ID,
                    Name       = cat.CategoryName,
                    Assigned   = gameCategories.Contains(cat.ID)
                });
            }
        }
        public void UpdateGameCategories(FinalProjectContext context,
                                         string[] selectedCategories, Game gameToUpdate)
        {
            if (selectedCategories == null)
            {
                gameToUpdate.GameCategories = new List <GameCategory>();
                return;
            }
            var selectedCategoriesHS = new HashSet <string>(selectedCategories);
            var gameCategories       = new HashSet <int>
                                           (gameToUpdate.GameCategories.Select(c => c.Category.ID));

            foreach (var cat in context.Category)
            {
                if (selectedCategoriesHS.Contains(cat.ID.ToString()))
                {
                    if (!gameCategories.Contains(cat.ID))
                    {
                        gameToUpdate.GameCategories.Add(
                            new GameCategory
                        {
                            GameID     = gameToUpdate.ID,
                            CategoryID = cat.ID
                        });
                    }
                }
                else
                {
                    if (gameCategories.Contains(cat.ID))
                    {
                        GameCategory courseToRemove
                            = gameToUpdate
                              .GameCategories
                              .SingleOrDefault(i => i.CategoryID == cat.ID);
                        context.Remove(courseToRemove);
                    }
                }
            }
        }
Exemplo n.º 4
0
 public DetailsModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 5
0
 public IndexModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public CreateModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 7
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new FinalProjectContext(serviceProvider.GetRequiredService <DbContextOptions <FinalProjectContext> >()))
            {
                // CLIENTS
                if (context.Clients.Any())
                {
                    //leave, there is already data in the database
                    return;
                }

                var clients = new List <Client>
                {
                    new Client {
                        FirstName = "Jimmie", LastName = "Ramos", CompanyName = "ACME", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Client {
                        FirstName = "Kristy", LastName = "Miles", CompanyName = "World Wide Industries", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Client {
                        FirstName = "Shelley", LastName = "Walker", CompanyName = "Big Money Inc", Email = "*****@*****.**", Phone = "555-555-5555"
                    }
                };
                context.AddRange(clients);
                context.SaveChanges();


                // CLIENTS
                if (context.Members.Any())
                {
                    //leave, there is already data in the database
                    return;
                }

                var members = new List <Member>
                {
                    new Member {
                        FirstName = "Mamie", LastName = "Santiago", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Pete", LastName = "Perez", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Flora", LastName = "Williamson", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Laverne", LastName = "Wolfe", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Delia", LastName = "Bridges", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Rebecca", LastName = "Morton", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    },
                    new Member {
                        FirstName = "Franklin", LastName = "Arnold", Major = "CIS", Email = "*****@*****.**", Phone = "555-555-5555"
                    }
                };
                context.AddRange(members);
                context.SaveChanges();

                // PROJECTS
                if (context.Projects.Any())
                {
                    //leave, there is already data in the database
                    return;
                }

                var projects = new List <Project>
                {
                    new Project {
                        ProjectName = "The Big One", ProjectDescription = "The One Project to rule them all"
                    },
                    new Project {
                        ProjectName = "Awesome", ProjectDescription = "This project is awesome"
                    },
                    new Project {
                        ProjectName = "Easy Project", ProjectDescription = "This project is so easy, it completes itself"
                    }
                };
                context.AddRange(projects);
                context.SaveChanges();

                //PROJECT ROSTER BRIDGE TABLE - THERE MUST BE PROJECTS AND PARTICIPANTS MADE FIRST
                if (context.ProjectRoster.Any())
                {
                    //leave, there is already data in the database
                    return;
                }



                //quickly grab the recent records added to the DB to get the IDs
                var projectsFromDb = context.Projects.ToList();
                var clientsFromDb  = context.Clients.ToList();
                var membersFromDb  = context.Members.ToList();

                var projectroster = new List <ProjectRoster>
                {
                    //take the first project from above, the first client from above, and the first three students from above.
                    new ProjectRoster {
                        ProjectID            = projectsFromDb.ElementAt(0).ID.ToString(),
                        Project              = projectsFromDb.ElementAt(0),
                        ProjectParticipantID = clientsFromDb.ElementAt(0).ID.ToString(),
                        ProjectParticipant   = clientsFromDb.ElementAt(0)
                    },

                    new ProjectRoster {
                        ProjectID            = projectsFromDb.ElementAt(0).ID.ToString(),
                        Project              = projectsFromDb.ElementAt(0),
                        ProjectParticipantID = membersFromDb.ElementAt(0).ID.ToString(),
                        ProjectParticipant   = membersFromDb.ElementAt(0)
                    },

                    new ProjectRoster {
                        ProjectID            = projectsFromDb.ElementAt(0).ID.ToString(),
                        Project              = projectsFromDb.ElementAt(0),
                        ProjectParticipantID = membersFromDb.ElementAt(1).ID.ToString(),
                        ProjectParticipant   = membersFromDb.ElementAt(1)
                    },

                    new ProjectRoster {
                        ProjectID            = projectsFromDb.ElementAt(0).ID.ToString(),
                        Project              = projectsFromDb.ElementAt(0),
                        ProjectParticipantID = membersFromDb.ElementAt(2).ID.ToString(),
                        ProjectParticipant   = membersFromDb.ElementAt(2)
                    },
                };
                context.AddRange(projectroster);
                context.SaveChanges();
            }
        }
Exemplo n.º 8
0
 public EditModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 9
0
 public MembershipProfileModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 10
0
 public SearchModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 11
0
 public TrainerProfileModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }
Exemplo n.º 12
0
 public ChangePlanModel(FinalProject.Models.FinalProjectContext context)
 {
     _context = context;
 }