Example #1
0
        // Practitioner Schedule (template) Queries
        public static List <PSchedule> OnePsSchedules(int pID, ProjectContext db)
        {
            List <PSchedule> existingPSs = db.PSchedules
                                           .Include(ps => ps.Practitioner)
                                           .Where(ps => ps.PractitionerId == pID)
                                           .OrderByDescending(ps => ps.UpdatedAt)
                                           .ToList();

            if (existingPSs.Count != 7) // if there are 0, or if an error has happened and more or less than 7 exist, let's reset
            {
                foreach (PSchedule oldPS in existingPSs)
                {
                    db.Remove(oldPS);
                }
                db.SaveChanges();
                string[] days = new string[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
                foreach (string day in days)
                {
                    PSchedule newPS = new PSchedule();
                    newPS.DayOfWeek      = day;
                    newPS.PractitionerId = pID;
                    newPS.Approved       = false;
                    db.Add(newPS);
                }
                db.SaveChanges();
                existingPSs = db.PSchedules
                              .Include(ps => ps.Practitioner)
                              .Where(ps => ps.PractitionerId == pID)
                              .OrderByDescending(ps => ps.UpdatedAt)
                              .ToList();
            }
            return(existingPSs);
        }
Example #2
0
        public static bool CreatePSchedule(ProjectContext db, int PracId)
        {
            User      practitioner = db.Users.FirstOrDefault(u => u.UserId == PracId);
            PSchedule monday       = new PSchedule();

            monday.PractitionerId = practitioner.UserId;
            monday.DayOfWeek      = "Monday";
            db.Add(monday);
            PSchedule tuesday = new PSchedule();

            tuesday.PractitionerId = practitioner.UserId;
            tuesday.DayOfWeek      = "Tuesday";
            db.Add(tuesday);
            PSchedule wednesday = new PSchedule();

            wednesday.PractitionerId = practitioner.UserId;
            wednesday.DayOfWeek      = "Wednesday";
            db.Add(wednesday);
            PSchedule thursday = new PSchedule();

            thursday.PractitionerId = practitioner.UserId;
            thursday.DayOfWeek      = "Thursday";
            db.Add(thursday);
            PSchedule friday = new PSchedule();

            friday.PractitionerId = practitioner.UserId;
            friday.DayOfWeek      = "Friday";
            return(true);
        }
Example #3
0
        public static List <PSchedule> ScheduleToQuery(Dictionary <string, Dictionary <string, bool> > frontEndPS, int practID)
        {
            List <PSchedule> queryReadyList = new List <PSchedule>();

            foreach (KeyValuePair <string, Dictionary <string, bool> > outerKVP in frontEndPS)
            {
                PSchedule thisPS = new PSchedule();
                thisPS.DayOfWeek      = outerKVP.Key;
                thisPS.PractitionerId = practID;
                thisPS.Approved       = false;
                foreach (KeyValuePair <string, bool> innerKVP in outerKVP.Value)
                {
                    string unParsedHour = innerKVP.Key.Substring(0, 4);
                    string parsedHour   = "";
                    int    numHour      = Int32.Parse(unParsedHour[0].ToString());
                    if (unParsedHour[0] == '1' && unParsedHour[1] != 'p')
                    {
                        parsedHour = unParsedHour.Substring(0, 2);
                    }
                    else if (unParsedHour[1] == 'p') // like 3pm, numhour is 3, needs to add 12 so it's 15
                    {
                        parsedHour = (numHour + 12).ToString();
                    }
                    else   // am, like 9am, numhour is 9 so just set it to parsedHour
                    {
                        parsedHour = numHour.ToString();
                    }
                    thisPS.GetType().GetProperty("t" + parsedHour).SetValue(thisPS, innerKVP.Value);
                }
                queryReadyList.Add(thisPS);
            }
            return(queryReadyList);
        }