Ejemplo n.º 1
0
        public static void GenerateTodaysTimeslots(ProjectContext db)
        {
            List <User> allPs   = db.Users.Include(u => u.PSchedules).Where(u => u.Role == 1).ToList(); // all practitioners (user role 1) including their schedules
            int         minHour = 6;
            int         maxHour = 18;

            for (int h = minHour; h <= maxHour; h++)
            {
                Timeslot newTS = new Timeslot();
                newTS.Date = DateTime.Today;
                newTS.Hour = h;
                db.Add(newTS);
                foreach (User p in allPs)
                {
                    foreach (PSchedule ps in p.PSchedules)
                    {
                        if (ps.DayOfWeek == newTS.Date.DayOfWeek.ToString())
                        {
                            // objName.GetType().GetProperty("propName").GetValue(objName); // this is code format for getting a property using a string for the property name
                            bool isPAvailNow = (bool)ps.GetType().GetProperty("t" + h).GetValue(ps); // adds the letter t to the integer of the timeslot's hour and gets that property value from the practitioner schedule to see if they are available
                            if (isPAvailNow)
                            {
                                PAvailTime pat = new PAvailTime();
                                pat.PractitionerId = ps.PractitionerId;
                                pat.TimeslotId     = newTS.TimeslotId;
                                db.Add(pat);
                            }
                        }
                    }
                }
            }
            db.SaveChanges();
            return;
        }
Ejemplo n.º 2
0
        public static void DeletePractitionerAvailability(int patID, ProjectContext db)
        {
            PAvailTime patToDel = db.PAvailTimes.FirstOrDefault(pat => pat.PAvailTimeId == patID);

            db.Remove(patToDel);
            db.SaveChanges();
            return;
        }
Ejemplo n.º 3
0
        public static PAvailTime CreatePractitionerAvailability(int pID, int tsID, ProjectContext db)
        {
            PAvailTime newPAT = new PAvailTime();

            newPAT.PractitionerId = pID;
            newPAT.TimeslotId     = tsID;
            db.Add(newPAT);
            db.SaveChanges();
            return(db.PAvailTimes
                   .Include(pat => pat.Practitioner)
                   .Include(pat => pat.TimeSlot)
                   .Where(pat => pat.PractitionerId == pID)
                   .FirstOrDefault(pat => pat.TimeslotId == tsID));
        }
Ejemplo n.º 4
0
        // Generate New Entries
        public static void GenerateTimeslots(int daysToBuild, Timeslot lastTS, ProjectContext db)
        {
            System.Console.WriteLine($"Beginning Timeslot Generation at {DateTime.Now}");
            DateTime    startTime = DateTime.Now;
            List <User> allPs     = db.Users.Include(u => u.PSchedules).Where(u => u.Role == 1).ToList(); // all practitioners (user role 1) including their schedules
            int         minHour   = 6;
            int         maxHour   = 18;

            for (int d = 1; d < daysToBuild; d++)
            {
                for (int h = minHour; h <= maxHour; h++)
                {
                    // generate new timeslot for each hour of each day we are adding
                    Timeslot newTS = new Timeslot();
                    if (lastTS == null)
                    {
                        newTS.Date = DateTime.Today.AddDays(d);
                    }
                    else
                    {
                        newTS.Date = lastTS.Date.AddDays(d);
                    }
                    newTS.Hour = h;
                    db.Add(newTS);
                    // generate new PAvailTimes to connect practitioners to each timeslot if their PSchedule lists them as available at this time/day
                    foreach (User p in allPs)
                    {
                        foreach (PSchedule ps in p.PSchedules)
                        {
                            if (ps.DayOfWeek == newTS.Date.DayOfWeek.ToString())
                            {
                                // objName.GetType().GetProperty("propName").GetValue(objName); // this is code format for getting a property using a string for the property name
                                bool isPAvailNow = (bool)ps.GetType().GetProperty("t" + h).GetValue(ps); // adds the letter t to the integer of the timeslot's hour and gets that property value from the practitioner schedule to see if they are available
                                if (isPAvailNow)
                                {
                                    PAvailTime pat = new PAvailTime();
                                    pat.PractitionerId = ps.PractitionerId;
                                    pat.TimeslotId     = newTS.TimeslotId;
                                    db.Add(pat);
                                }
                            }
                        }
                    }
                }
            }
            db.SaveChanges();
            System.Console.WriteLine($"Timeslot Generation completed at {DateTime.Now}");
            System.Console.WriteLine($"Time taken: {(DateTime.Now - startTime).TotalSeconds} seconds");
        }
Ejemplo n.º 5
0
        public static List <PSchedule> UpdateAllOfOnePsSchedules(int pID, List <PSchedule> updatedPSchedules, ProjectContext db)
        {
            if (updatedPSchedules.Count != 7)
            {
                System.Console.WriteLine("Error: The list of PSchedules provided to update didn't contain 7 PSchedules!  You need one for each day!");
                return(updatedPSchedules);
            }
            List <PSchedule> oldPSs = db.PSchedules.Where(ps => ps.PractitionerId == pID).ToList();

            foreach (PSchedule oldPS in oldPSs)
            {
                db.Remove(oldPS);
            }
            db.SaveChanges();
            List <PAvailTime> thisPsPats = Query.OnePractitionersAvailabilities(pID, db);

            foreach (PAvailTime patToDel in thisPsPats)
            {
                db.Remove(patToDel);
            }
            db.SaveChanges();
            foreach (PSchedule newPS in updatedPSchedules)
            {
                db.Add(newPS);
                for (int h = 6; h <= 18; h++)
                {
                    if ((bool)newPS.GetType().GetProperty("t" + h).GetValue(newPS))
                    {
                        List <Timeslot> matchingTSs = db.Timeslots.Where(ts => ts.Date.DayOfWeek.ToString() == newPS.DayOfWeek)
                                                      .Where(ts => ts.Hour == h).ToList();
                        foreach (Timeslot tsToAdd in matchingTSs)
                        {
                            PAvailTime newPat = new PAvailTime();
                            newPat.TimeslotId     = tsToAdd.TimeslotId;
                            newPat.PractitionerId = pID;
                            db.Add(newPat);
                        }
                    }
                }
            }
            db.SaveChanges();
            return(updatedPSchedules);
        }
Ejemplo n.º 6
0
        public static List <PAvailTime> UpdateAllOfOnePsAvails(int pID, List <PAvailTime> updatedPATs, ProjectContext db)
        {
            List <PAvailTime> oldPats = db.PAvailTimes.Where(pat => pat.PractitionerId == pID).ToList();

            foreach (PAvailTime oldPat in oldPats)
            {
                PAvailTime patToDel = db.PAvailTimes.FirstOrDefault(pat => pat.PAvailTimeId == oldPat.PAvailTimeId);
                db.Remove(patToDel);
            }
            db.SaveChanges();
            foreach (PAvailTime updatedPat in updatedPATs)
            {
                PAvailTime newPAT = new PAvailTime();
                newPAT.PractitionerId = updatedPat.PractitionerId;
                newPAT.TimeslotId     = updatedPat.TimeslotId;
                db.Add(newPAT);
            }
            db.SaveChanges();
            return(db.PAvailTimes
                   .Include(pat => pat.Practitioner)
                   .Include(pat => pat.TimeSlot)
                   .Where(pat => pat.PractitionerId == pID)
                   .ToList());
        }