// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ClubContext context)
        {
            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();
            DBSeeder.SeedDB(context);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Пример #2
0
 public PlayerStatController(IPersonRepository personRepository, ClubContext context, IPlayerStatRepository playerStatRepository, ILogger <PlayerStatController> logger)
 {
     _personRepository     = personRepository;
     _playerStatRepository = playerStatRepository;
     _context = context;
     _logger  = logger;
 }
Пример #3
0
        public static void SeedStudentCourses(ClubContext context)
        {
            var randomSetStudent = context.Students.Where(s => !context.StudentCourses.Any(sc => sc.StudentID == s.StudentID))
                                   .Select(s => new { s.StudentID, r = Guid.NewGuid() });
            List <string> subset = randomSetStudent.OrderBy(s => s.r)
                                   .Select(s => s.StudentID.ToString())
                                   .Take(4).ToList();
            var randomCourseSet = context.Courses.Select(c => new { c.CourseID, r = Guid.NewGuid() });
            int courseID        = randomCourseSet.OrderBy(c => c.r)
                                  .Select(c => c.CourseID)
                                  .Take(1).ToList()[0];

            foreach (var data in subset)
            {
                context.StudentCourses.AddOrUpdate(sc =>
                                                   new { sc.StudentID, sc.CourseID },
                                                   new StudentCourse
                {
                    StudentID = data,
                    CourseID  = courseID
                });
            }

            context.SaveChanges();
        }
Пример #4
0
        //seed new club member
        private void SeedClubMembers(ClubContext context)
        {
            // Create a list to hold students
            List <Student> selectedStudents = new List <Student>();

            //save newly created clubs first , then retrieve them as a list
            foreach (var club in context.Clubs.ToList())
            {
                //set member if not set yet
                if (club.clubMembers == null || club.clubMembers.Count() < 1)
                {
                    //set randoms one --method below
                    selectedStudents = GetStudents(context);
                    foreach (var m in selectedStudents)
                    {
                        //new member with a ref to a club ,EF will join fields later
                        context.members.AddOrUpdate(member => member.StudentID,
                                                    new Member {
                            ClubId = club.ClubId, StudentID = m.StudentID
                        });
                    }
                }
            }
            context.SaveChanges();
        }
Пример #5
0
        //seed courses details
        public static void SeedCourses(ClubContext context)
        {
            Assembly assembly     = Assembly.GetExecutingAssembly();
            string   resourceName = "Rad301ClubsV1.Migrations.ClubModelMigrations.Courses.csv";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    CsvReader csvReader = new CsvReader(reader);
                    csvReader.Configuration.HasHeaderRecord = false;
                    var courseData = csvReader.GetRecords <CourseDataImport>().ToArray();
                    foreach (var dataItem in courseData)
                    {
                        context.Courses.AddOrUpdate(c =>
                                                    new { c.CourseCode, c.CourseName },
                                                    new Course
                        {
                            CourseCode = dataItem.CourseCode,
                            CourseName = dataItem.CourseName,
                            CourseYear = dataItem.Year
                        });
                    }
                }
            }
            context.SaveChanges();
        }
Пример #6
0
        private void SeedClubMembersApplicationUsers(UserManager <ApplicationUser> manager, ApplicationDbContext context)
        {
            List <Member> members;
            // Create Application Logins for all seeded members
            ClubContext clubc = new ClubContext();

            members = clubc.ClubMembers.ToList();

            PasswordHasher ps = new PasswordHasher();

            foreach (var member in members)
            {
                ApplicationUser user = manager.FindByEmail(member.StudentID + "@mail.itsligo.ie");
                if (user == null)
                {
                    context.Users.AddOrUpdate(u => u.UserName,
                                              new ApplicationUser
                    {
                        ClubEntityID   = member.StudentID,
                        FirstName      = member.studentMember.FirstName,
                        Surname        = member.studentMember.SecondName,
                        Email          = member.StudentID + "@mail.itsligo.ie",
                        UserName       = member.StudentID + "@mail.itsligo.ie",
                        EmailConfirmed = true,
                        JoinDate       = DateTime.Now,
                        SecurityStamp  = Guid.NewGuid().ToString(),
                        PasswordHash   = ps.HashPassword(member.StudentID + "s$1")
                    });
                }
            }
        }
        public static void SeedCourses(ClubContext context)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            // You'll need to change this reference in the Club MVC app
            // as it has a different namespace
            string resourceName = "EFConsoleApp.Migrations.Courses.csv";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    CsvReader csvReader = new CsvReader(reader);
                    csvReader.Configuration.HasHeaderRecord = false;
                    var courseData = csvReader.GetRecords <CourseDataImport>().ToArray();
                    foreach (var dataItem in courseData)
                    {
                        context.Courses.AddOrUpdate(c =>
                                                    new { c.CourseCode, c.CourseName },
                                                    new Course {
                            CourseCode = dataItem.CourseCode,
                            CourseName = dataItem.CourseName,
                            Year       = dataItem.Year
                        });
                    }
                }
            }
            context.SaveChanges();
        }
 static void Main(string[] args)
 {
     using (ClubContext context = new ClubContext())
     {
         SeedClub(context);
         SeedStudents(context);
     }
 }
 public PeopleController(ClubContext context, IPlayerStatRepository playerStat, ITeamRepository teamRepository, IBlobStorageService storageService, ILogger <PeopleController> logger)
 {
     _context        = context;
     _playerStat     = playerStat;
     _teamRepository = teamRepository;
     _blobService    = storageService;
     _logger         = logger;
 }
        public static List <Member> getMembers(ClubContext context)
        {
            var ret = GetStudents(context).Select(s => new Member {
                StudentID = s.StudentID
            }).ToList();

            return(ret);
        }
        // This is debuggable
        private static void SeedClub(ClubContext context)
        {
            #region club 1
            context.Clubs.AddOrUpdate(c => c.ClubName,

                                      new Club
            {
                //clubMembers=getMembers(context),
                ClubName     = "The Tiddly Winks Club",
                CreationDate = DateTime.Now,
                adminID      = -1, // Choosing a negative to define unassigned as all members will have a positive id later
                // It seem you cannot reliably assign the result of a method to a field while using
                // Add Or Update. My suspicion is that it cannot evaluate whether
                // or not it is an update. There could also be a EF version issue
                // The club events assignment will work though as it is
                clubEvents = new List <ClubEvent>()
                { // Create a new ClubEvent
                    new ClubEvent {
                        StartDateTime = DateTime.Now.Subtract(new TimeSpan(5, 0, 0, 0, 0)),
                        EndDateTime   = DateTime.Now.Subtract(new TimeSpan(5, 0, 0, 0, 0)),
                        Location      = "Sligo", Venue = "Arena",
                        // Update attendees with a method similar to the SeedClubMembers
                        // See below
                    },
                    new ClubEvent {
                        StartDateTime = DateTime.Now.Subtract(new TimeSpan(3, 0, 0, 0, 0)),
                        EndDateTime   = DateTime.Now.Subtract(new TimeSpan(3, 0, 0, 0, 0)),
                        Location      = "Sligo", Venue = "Main Canteen"
                    },
                }
            });
            #endregion
            #region club 2
            context.Clubs.AddOrUpdate(c => c.ClubName,
                                      new Club
            {
                ClubName     = "The Chess Club",
                CreationDate = DateTime.Now,
                adminID      = -1,
                clubEvents   = new List <ClubEvent>()
                {       // Create a new ClubEvent
                    new ClubEvent {
                        StartDateTime = DateTime.Now.Subtract(new TimeSpan(5, 0, 0, 0, 0)),
                        EndDateTime   = DateTime.Now.Subtract(new TimeSpan(6, 0, 0, 0, 0)),
                        Location      = "Sligo", Venue = "The Leitrim Bar",
                        // Update attendees with a method similar to the SeedClubMembers
                        // See below
                    },
                    new ClubEvent {
                        StartDateTime = DateTime.Now.Subtract(new TimeSpan(3, 0, 0, 0, 0)),
                        EndDateTime   = DateTime.Now.Subtract(new TimeSpan(2, 0, 0, 0, 0)),
                        Location      = "Sligo", Venue = "Main Canteen"
                    },
                }
            });
            #endregion
            context.SaveChanges();
        }
        private IPersonRepository GetInMemoryPersonRepository()
        {
            var         builder         = new DbContextOptionsBuilder <ClubContext>().UseInMemoryDatabase(databaseName: "PersonListDb").Options;
            ClubContext clubDataContext = new ClubContext(builder);

            clubDataContext.Database.EnsureDeleted();
            clubDataContext.Database.EnsureCreated();
            return(new PersonRepository(clubDataContext));
        }
        private void Seed_club(ApplicationDbContext context, UserManager <ApplicationUser> manager)
        {
            ClubContext ctx  = new ClubContext();
            Club        club = ctx.Clubs.First();

            SeedClubMembersApplicationUsers(club, manager, context);
            SeedAdminMember(club, manager, context);
            ctx.SaveChanges();
        }
 public TeamController(IPersonRepository personRepository, ITeamRepository teamRepository, ClubContext context, IMailService mailService, IBlobStorageService storageService, ILogger <TeamController> logger)
 {
     _personRepository = personRepository;
     _teamRepository   = teamRepository;
     _context          = context;
     _mailService      = mailService;
     _blobService      = storageService;
     _logger           = logger;
 }
Пример #15
0
 private List <Club> GetAllClubs()
 {
     using (var context = new ClubContext())
     {
         var service = new ClubService(context);
         var clubs   = service.GetAll();
         return(clubs.ToList());
     }
 }
 public FixtureController(ClubContext context, IFixtureRepository fixtureRepository, ITeamRepository teamRepository, IPersonRepository personRepository, IPlayerStatRepository playerStatRepository, ILogger <FixtureController> logger)
 {
     _context              = context;
     _fixtureRepository    = fixtureRepository;
     _teamRepository       = teamRepository;
     _personRepository     = personRepository;
     _playerStatRepository = playerStatRepository;
     _logger = logger;
 }
 public static void ListClubs()
 {
     using (ClubContext clubContext = new ClubContext())
     {
         foreach (var item in clubContext.Clubs)
         {
             System.Console.WriteLine(item.ClubName);
         }
     }
 }
Пример #18
0
 private bool Valid(string clubEntityID)
 {
     using (ClubContext ctx = new ClubContext())
     {
         if (ctx.Students.FirstOrDefault(s => s.StudentID == clubEntityID) != null)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #19
0
        //random students method
        private List <Student> GetStudents(ClubContext context)
        {
            //random list of srudent ids
            var randomSetStudent = context.Students.Select(s => new { s.StudentID, r = Guid.NewGuid() });
            //sort and take 10
            List <string> subset = randomSetStudent.OrderBy(s => s.r)
                                   .Select(s => s.StudentID.ToString()).Take(10).ToList();

            //return sel students as a relaized list
            return(context.Students.Where(s => subset.Contains(s.StudentID)).ToList());
        }
Пример #20
0
 static void Main(string[] args)
 {
     using (ClubContext context = new ClubContext())
     {
         SeedClub(context);
         GetStudents(context);
         getMembers(context);
         SeedStudents(context);
         SeedCourses(context);
     }
 }
        public static List <Course> GetCourses(ClubContext context)
        {
            // Create a random list of student ids
            var randomCourse = context.Courses.Select(c => new { c.CourseCode, r = Guid.NewGuid() });
            // sort them and take 10
            List <string> subset = randomCourse.OrderBy(s => s.r)
                                   .Select(s => s.CourseCode.ToString()).Take(1).ToList();

            // return the selected students as a relaized list
            return(context.Courses.Where(s => subset.Contains(s.CourseCode)).ToList());
        }
Пример #22
0
 private Student GetStudent(string clubEntityID)
 {
     using (ClubContext ctx = new ClubContext())
     {
         Student student;
         if ((student = ctx.Students.FirstOrDefault(s => s.StudentID == clubEntityID)) != null)
         {
             return(student);
         }
     }
     return(null);
 }
        private void seed_Db_model(ClubContext context)
        {
            CultureInfo cultureinfo = CultureInfo.CreateSpecificCulture("en-IE");

            context.Clubs.AddOrUpdate(new Club[]
            {
                new Club {
                    ClubName     = "The Chess Club",
                    CreationDate = DateTime.ParseExact("25/01/2017", "dd/mm/yyyy", cultureinfo),
                }, // End of Club
            } // End of Clubs
                                      );
            context.SaveChanges();
        }
Пример #24
0
        public void SeedStudents(ApplicationDbContext current)
        {
            List <Student> selectedStudents = new List <Student>();

            using (ClubContext ctx = new ClubContext())
            {
                var randomStudentSet = ctx.Students
                                       .Select(s => new { s.StudentID, r = Guid.NewGuid() });

                List <string> subset = randomStudentSet.OrderBy(s => s.r).Select(s => s.StudentID).Take(10).ToList();

                foreach (string s in subset)
                {
                    selectedStudents.Add(
                        ctx.Students.First(st => st.StudentID == s)
                        );
                }

                Club chosen = ctx.Clubs.First();

                foreach (Student s in selectedStudents)
                {
                    ctx.members.AddOrUpdate(m => m.StudentID,
                                            new Member
                    {
                        ClubId    = chosen.ClubId,
                        StudentID = s.StudentID
                    });
                }
                ctx.SaveChanges();
            }

            // Add application users
            foreach (Student s in selectedStudents)
            {
                current.Users.AddOrUpdate(u => u.StudentID,
                                          new ApplicationUser
                {
                    StudentID      = s.StudentID,
                    UserName       = s.StudentID + "@mail.itsligo.ie",
                    Email          = s.StudentID + "@mail.itsligo.ie",
                    EmailConfirmed = true,
                    DateJoined     = DateTime.Now,
                    PasswordHash   = new PasswordHasher().HashPassword(s.StudentID + "$1"),
                    SecurityStamp  = Guid.NewGuid().ToString(),
                });
            }
            current.SaveChanges();
        }
 public ManageController(
     ClubContext context,
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IEmailSender emailSender,
     ISmsSender smsSender,
     ILoggerFactory loggerFactory)
 {
     _context       = context;
     _userManager   = userManager;
     _signInManager = signInManager;
     _emailSender   = emailSender;
     _smsSender     = smsSender;
     _logger        = loggerFactory.CreateLogger <ManageController>();
 }
Пример #26
0
        // Seeding admins for all clubs
        private void SeedAllClubAdmin(UserManager <ApplicationUser> manager, ApplicationDbContext context)
        {
            ClubContext clubc            = new ClubContext();
            List <Club> ClubsWithNoAdmin = clubc.Clubs.Where(c => c.adminID == 0).ToList();

            // if there are any clubs with no admin
            if (ClubsWithNoAdmin.Count() > 0)
            {
                foreach (var club in ClubsWithNoAdmin)
                {
                    // Seed a member for that club
                    SeedAdminMember(clubc, manager, context, club);
                }
            }
            clubc.SaveChanges();
        }
        private static void addMemberstoClub(ClubContext ctx, Club club)
        {
            List <string> RandomSIDs = ctx.Students.Select(
                s => new { s.StudentID, gid = Guid.NewGuid() })
                                       .OrderBy(g => g.gid)
                                       .Select(s => s.StudentID)
                                       .ToList();
            List <ClubDomain.Classes.ClubModels.Student> sublist =
                ctx.Students.Where(s => RandomSIDs.Contains(s.StudentID)).Take(3).ToList();

            foreach (var item in sublist)
            {
                //ClubWithNoMembers.clubMembers.Add(new Member { });
                System.Console.WriteLine("Adding {0} to Club ", item.StudentID, club.ClubId);
            }
        }
Пример #28
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                // Check that the Id has not been used before
                using (ApplicationDbContext db = new ApplicationDbContext())
                {
                    var usr = db.Users.FirstOrDefault(u => u.StudentID.ToUpper() == model.StudentID.ToUpper());
                    if (usr != null)
                    {
                        ModelState.AddModelError("Invalid Student ID", "Student ID has already been used for registration" + model.StudentID);
                        return(View(model));
                    }
                }
                // Check that the ID being used is valid
                using (ClubContext ctx = new ClubContext())
                {
                    var existing = ctx.Students.FirstOrDefault(s => s.StudentID.ToUpper() == model.StudentID.ToUpper());
                    if (existing == null)
                    {
                        ModelState.AddModelError("Student ID does not exist in our records", "Student ID does not exist in our records" + model.StudentID);
                        return(View(model));
                    }
                }
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, DateJoined = DateTime.Now
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
                    string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Confirm your account");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        private void seed_Db_ClubMembers(ClubContext context)
        {
            Club firstClub = context.Clubs.First();

            // Make an array of members from the first 10 selected students
            Member[] NewMembers = context.Students
                                  .Take(10).ToList()
                                  .Select(s => // Making the Member output
                                          new Member {
                StudentID      = s.StudentID,
                approved       = false,
                AssociatedClub = firstClub.ClubId
            })
                                  .ToArray();
            context.ClubMembers.AddOrUpdate(c => c.StudentID,
                                            NewMembers);
        }
Пример #30
0
        public static void SeedStudents(ClubContext context)
        {
            Assembly assembly     = Assembly.GetExecutingAssembly();
            string   resourceName = "EFConsoleApp.Migrations.TestStudents.csv";

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
            {
                using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
                {
                    CsvReader csvReader = new CsvReader(reader);
                    csvReader.Configuration.HasHeaderRecord = false;
                    var testStudents = csvReader.GetRecords <Student>().ToArray();
                    context.Students.AddOrUpdate(s => s.StudentID, testStudents);
                }
            }
            context.SaveChanges();
        }