public void GetStudentRequestsTest()
        {
            // ARRANGE
            LectorService   service = new LectorService(ctxDb);
            ApplicationUser user1   = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Cleas", VoorNaam = "Thomas", EmailConfirmed = true
            };
            ApplicationUser user2 = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Haesevoets", VoorNaam = "Jaimie", EmailConfirmed = true
            };
            ApplicationUser user3 = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "VanBeal", VoorNaam = "Rik", EmailConfirmed = true
            };

            ctxDb.Users.Add(user1);
            ctxDb.Users.Add(user2);
            ctxDb.Users.Add(user3);
            ctxDb.SaveChanges();

            string userId1 = ctxDb.Users.Where(u => u.UserName == "r0664186").FirstOrDefault().Id;
            string userId2 = ctxDb.Users.Where(u => u.UserName == "r1234567").FirstOrDefault().Id;
            string userId3 = ctxDb.Users.Where(u => u.UserName == "r2345678").FirstOrDefault().Id;

            Course course = new Course {
                Vakcode = "MGP01A", Titel = "front end", Studiepunten = 6, FieldOfStudyId = 123
            };

            ctxDb.Course.Add(course);
            ctxDb.SaveChanges();

            int courseId1 = ctxDb.Course.Where(c => c.Vakcode == "MGP01A").FirstOrDefault().Id;

            CourseUser cu1 = new CourseUser {
                ApplicationUserId = userId1, CourseId = courseId1, GoedGekeurd = false
            };
            CourseUser cu2 = new CourseUser {
                ApplicationUserId = userId2, CourseId = courseId1, GoedGekeurd = true
            };
            CourseUser cu3 = new CourseUser {
                ApplicationUserId = userId3, CourseId = courseId1, GoedGekeurd = false
            };

            ctxDb.CourseUser.Add(cu1);
            ctxDb.CourseUser.Add(cu2);
            ctxDb.CourseUser.Add(cu3);
            ctxDb.SaveChanges();

            // ACT
            var requests = service.GetStudentRequests();

            // ASSERT
            Assert.IsTrue(requests.Count == 2);

            for (int i = 1; i < requests.Count; i++)
            {
                Assert.IsTrue(requests[i].RNum == user1.UserName || requests[i].RNum == user3.UserName);
            }
        }
예제 #2
0
        private async Task <LokaalController> SetupLokaalController(LokaalService service)
        {
            ctxDb.Roles.Add(new IdentityRole {
                Name = "Student", NormalizedName = "STUDENT"
            });
            ctxDb.SaveChanges();

            AccountService accService = new AccountService(userManager, signInManager);
            var            user       = await accService.RegisterUser(new RegisterViewModel { RNum = "r0000001", Email = "*****@*****.**", Name = "Thomas", SurName = "Claes", Password = "******", ConfirmPassword = "******", GeboorteDatum = new DateTime(1998, 9, 21) });

            IOptions <IdentityOptions> options = Options.Create <IdentityOptions>(new IdentityOptions {
            });

            UserClaimsPrincipalFactory <ApplicationUser> userClaimFactory = new UserClaimsPrincipalFactory <ApplicationUser>(userManager, options);

            var claim = userClaimFactory.CreateAsync(user).Result;

            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(x => x.User).Returns(claim);

            var context = new ControllerContext(new ActionContext(httpContext.Object, new RouteData(), new ControllerActionDescriptor()));

            return(new LokaalController(service)
            {
                ControllerContext = context, TempData = new TempDataDictionary(httpContext.Object, Mock.Of <ITempDataProvider>())
            });
        }
예제 #3
0
        public void AddVak(string vakcode, string titel, int studiepunten)
        {
            var cInUse = from c in db.Course
                         where c.Vakcode == vakcode
                         select c;

            if (cInUse.Any())
            {
                throw new ArgumentException("Vak met deze vakcode bestaat reeds.");
            }

            Course course = new Course {
                Vakcode = vakcode.ToUpper(), Titel = titel, Studiepunten = studiepunten
            };

            FieldOfStudy FOS = db.FieldOfStudy.Where(fos => fos.RichtingCode == vakcode.Substring(0, 3)).FirstOrDefault();


            if (FOS != null)
            {
                course.FieldOfStudyId     = FOS.Id;
                FOS.RichtingStudiepunten += course.Studiepunten;
            }

            db.Course.Add(course);
            db.SaveChanges();
        }
        public void AddRichting(string code, string titel, string type)
        {
            var rInUse = from r in db.FieldOfStudy
                         where r.RichtingCode == code.ToUpper()
                         select r;

            if (rInUse.Any())
            {
                throw new ArgumentException("Richting met deze code bestaat reeds.");
            }

            FieldOfStudy fos = new FieldOfStudy {
                RichtingCode = code.ToUpper(), RichtingTitel = titel.ToLower(), Type = type.ToLower(), RichtingStudiepunten = 0
            };

            db.FieldOfStudy.Add(fos);
            db.SaveChanges();
        }
        public void AddLokaal(string gebouw, int verdiep, string nummer, string type, int capaciteit, string middelen)
        {
            var rInUse = from d in db.Room
                         where d.Gebouw == gebouw
                         where d.Verdiep == verdiep
                         where d.Nummer == nummer
                         select d;

            if (rInUse.Any())
            {
                throw new ArgumentException("Dit lokaal bestaat reeds.");
            }

            Room room = new Room {
                Gebouw = gebouw.ToUpper(), Verdiep = verdiep, Nummer = nummer, Type = type, Capaciteit = capaciteit, Middelen = middelen
            };

            db.Room.Add(room);
            db.SaveChanges();
        }
        public async Task GetAllFieldOfStudyTest()
        {
            // ARRANGE
            FieldOfStudyService service = new FieldOfStudyService(ctxDb);
            FieldOfStudy        FOS1    = new FieldOfStudy {
                RichtingCode = "MGP", RichtingTitel = "Model graduaat programmeren", Type = "Graduaat", RichtingStudiepunten = 60
            };
            FieldOfStudy FOS2 = new FieldOfStudy {
                RichtingCode = "MBI", RichtingTitel = "Model bachelor informatica", Type = "bachelor", RichtingStudiepunten = 90
            };
            FieldOfStudy FOS3 = new FieldOfStudy {
                RichtingCode = "MBC", RichtingTitel = "Model bachelor chemie", Type = "bachelor", RichtingStudiepunten = 120
            };

            ctxDb.FieldOfStudy.Add(FOS1);
            ctxDb.FieldOfStudy.Add(FOS2);
            ctxDb.FieldOfStudy.Add(FOS3);

            ctxDb.SaveChanges();

            // ACT
            var fosList = service.GetAllFieldOfStudy();

            // ASSERT
            Assert.IsTrue((await fosList.FirstOrDefaultAsync()).RichtingCode == "MBC");
        }
예제 #7
0
        public async Task <IdentityResult> DeleteUser(string id)
        {
            var user = await userManager.FindByIdAsync(id);

            if (user == null)
            {
                throw new Exception("De user met id: " + id + " kon niet gevonden worden.");
            }
            else
            {
                var qryDelUCMU = from cmu in db.CourseMomentUsers
                                 where cmu.ApplicationUserId == user.Id
                                 select cmu;

                if (qryDelUCMU.Any())
                {
                    foreach (var CoUs in qryDelUCMU)
                    {
                        db.CourseMomentUsers.Remove(CoUs);
                    }
                    db.SaveChanges();
                }

                var qryDelUCU = from cu in db.CourseUser
                                where cu.ApplicationUserId == user.Id
                                select cu;

                if (qryDelUCU.Any())
                {
                    foreach (var CoUs in qryDelUCU)
                    {
                        db.CourseUser.Remove(CoUs);
                    }
                    db.SaveChanges();
                }

                return(await userManager.DeleteAsync(user));
            }
        }
        public async Task AddTest()
        {
            // ARRANGE
            PlannerService    service    = new PlannerService(ctxDb);
            PlannerController controller = SetupPlannerController(service).Result;

            Room room = new Room {
                Gebouw = "A", Verdiep = 1, Nummer = "01", Type = "Lokaal"
            };

            ctxDb.Room.Add(room);

            Course course = new Course {
                Vakcode = "AAA01A", Titel = "testvak", Studiepunten = 4
            };

            ctxDb.Course.Add(course);
            ctxDb.SaveChanges();

            string dat      = DateTime.Today.AddDays(1).ToString("yyyy-MM-dd");
            string uur      = "11:00";
            double duratie  = 2.0;
            int    lokaalId = ctxDb.Room.Where(r => r.Gebouw == "A" && r.Verdiep == 1 && r.Nummer == "01").FirstOrDefault().Id;
            int    vakId    = ctxDb.Course.Where(c => c.Vakcode == "AAA01A").FirstOrDefault().Id;

            // ACT
            var res = await controller.Add(dat, uur, lokaalId, duratie, vakId, null, null, 0);

            // ASSERT
            Assert.IsTrue(res is ActionResult);
            Assert.IsNotNull(ctxDb.CourseMoment.Where(cm => cm.CourseId == vakId && cm.RoomId == lokaalId).FirstOrDefault());
        }
        public void AddPlanningTest()
        {
            // ARRANGE
            PlannerService  service = new PlannerService(ctxDb);
            ApplicationUser user    = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", GeboorteDatum = new DateTime(1998, 09, 21), Naam = "Claes", VoorNaam = "Thomas", EmailConfirmed = true
            };

            ctxDb.Users.Add(user);

            Room room = new Room {
                Gebouw = "A", Verdiep = 1, Nummer = "01", Type = "Lokaal"
            };

            ctxDb.Room.Add(room);

            Course course = new Course {
                Vakcode = "AAA01A", Titel = "testvak", Studiepunten = 4
            };

            ctxDb.Course.Add(course);
            ctxDb.SaveChanges();

            var userFull = ctxDb.Users.Where(u => u.UserName == "r0664186").FirstOrDefault();
            int roomId   = ctxDb.Room.Where(r => r.Type == "Lokaal").FirstOrDefault().Id;
            int courseId = ctxDb.Course.Where(c => c.Vakcode == "AAA01A").FirstOrDefault().Id;

            DateTime datum   = new DateTime(DateTime.Now.Year, DateTime.Now.Month, (DateTime.Now.Day + 1));
            DateTime start   = new DateTime(1800, 1, 1, 11, 0, 0);
            double   duratie = 2.0;

            // ACT
            service.AddPlanning(userFull, datum, start, duratie, roomId, courseId, null, null, 3);

            // ASSERT
            Assert.IsTrue(ctxDb.CourseMoment.Any());
        }
        public void AddPlanning(ApplicationUser user, DateTime datum, DateTime tijd, double _duratie, int lokaalId, int vakid, string?lessenlijst, bool?checkbox, int lokaal2Id)
        {
            DateTime eindmoment = tijd.AddHours(_duratie);

            if (DubbeleBoeking(datum, tijd, eindmoment, lokaalId))
            {
                throw new Exception("Dit lokaal wordt reeds gebruikt in een anders lesmoment op dit tijdstip.");
            }

            //hier code schrijven zodat er niet altijd een nieuwe schedule wordt aangemaakt
            Schedule schedule = new Schedule {
                Datum = datum, Startmoment = tijd, Eindmoment = eindmoment
            };

            db.Schedule.Add(schedule);
            db.SaveChanges();

            CourseMoment moment = new CourseMoment {
                CourseId = vakid, ScheduleId = schedule.Id, RoomId = lokaalId, ApplicationUserId = user.Id, LessenLijst = lessenlijst
            };

            db.CourseMoment.Add(moment);
            db.SaveChanges();

            if (checkbox != null && checkbox == true)
            {
                if (DubbeleBoeking(datum, tijd, eindmoment, lokaal2Id))
                {
                    throw new Exception("Het lokaal voor de tweede les wordt reeds gebruikt in een anders lesmoment op dit tijdstip. Lesmoment 1 werd wel ingepland.");
                }

                CourseMoment moment2 = new CourseMoment {
                    CourseId = vakid, ScheduleId = schedule.Id, RoomId = lokaal2Id, ApplicationUserId = user.Id, LessenLijst = lessenlijst
                };

                //hier code schrijven zodat er geen tweede dezelfde coursemoment aangemaakt kan worden

                db.CourseMoment.Add(moment2);
                db.SaveChanges();
            }
        }
예제 #11
0
 public void ApproveStudent(int cuId)
 {
     db.CourseUser.Find(cuId).GoedGekeurd = true;
     db.SaveChanges();
 }