Exemple #1
0
        //filter out openings.
        private List <Openings> FilterOpenings(DateTime targetDate, TimeSlot timeSlot, InstallZone installZone)
        {
            TechDispatchContext       db               = new TechDispatchContext();
            IEnumerable <Appointment> Apps             = db.Appointments.Where(x => x.Date == targetDate);
            List <Openings>           SelectedOpenings = new List <Openings>();

            //we want to only pick days that are relevant.
            int day;

            if (DefaultOption)
            {
                day = (int)targetDate.DayOfWeek;
            }
            else
            {
                day = -1;
            }

            SelectedOpenings = db.Openings.Where(x => x.ScheduleID == ScheduleId && x.Day == day).OrderBy(x => x.InstallZone.Name).ThenBy(x => x.TimeSlot.Name).ToList();

            if (timeSlot != null)
            {
                SelectedOpenings = SelectedOpenings.Where(x => x.TimeSlotId == timeSlot.TimeSlotID).ToList();
                Apps             = Apps.Where(x => x.TimeSlot == timeSlot);
            }
            if (installZone != null)
            {
                SelectedOpenings = SelectedOpenings.Where(x => x.InstallZoneId == installZone.InstallZoneId).ToList();
                Apps             = Apps.Where(x => x.Customer.Tower.InstallZone == installZone);
            }

            return(SelectedOpenings);
        }
Exemple #2
0
        //filter available openings only.
        private List <Openings> AvailableOpenings(DateTime targetDate, TimeSlot timeSlot, InstallZone installZone, bool install = false)
        {
            TechDispatchContext       db   = new TechDispatchContext();
            IEnumerable <Appointment> Apps = db.Appointments.Where(x => x.Date == targetDate && x.CurrentState != Appointment.AppointmentState.Cancelled &&
                                                                   x.CurrentState != Appointment.AppointmentState.Failed && x.CurrentState != Appointment.AppointmentState.NeedsReschedule);
            List <Openings> SelectedOpenings = FilterOpenings(targetDate, timeSlot, installZone);

            //if applicable, a list of IDs that have been modified to account for minus one installs.

            foreach (var x in SelectedOpenings)
            {
                x.AvailableAmount = x.Amount;
            }

            foreach (var x in Apps)
            {
                try
                {
                    SelectedOpenings.DefaultIfEmpty(null).FirstOrDefault(y => y.InstallZoneId ==
                                                                         x.Customer.Tower.InstallZoneId && y.TimeSlotId == x.TimeSlotID).AvailableAmount--;
                }
                catch (NullReferenceException e)
                {
                    var y = 123123;
                }
            }

            if (install)
            {
                foreach (var x in SelectedOpenings)
                {
                    if (x.AvailableAmount > 0 && Apps.Where(y => x.InstallZoneId == y.Customer.Tower.InstallZoneId &&
                                                            x.TimeSlotId == y.TimeSlotID && y.AppointmentType != Appointment.AppointmentReason.Install).Count() == 0)
                    {
                        x.AvailableAmount--;
                    }
                }
            }

            return(SelectedOpenings);
        }
Exemple #3
0
        //filter to specific openings.
        public Schedule ScheduleWithFilter(DateTime targetDate, TimeSlot timeSlot = null, InstallZone installZone = null, bool install = false)
        {
            Openings.Clear();
            Openings = AvailableOpenings(targetDate, timeSlot, installZone, install);

            return(this);
        }