Пример #1
0
        /// <summary>
        /// Alle zukünftigen Sprechstunden bis Zeitpunkt
        /// </summary>
        /// <param name="until"></param>
        /// <returns></returns>
        public IEnumerable <LecturerOfficeHourContract> GetAllOfficehours(DateTime until)
        {
            var db = new TimeTableDbContext();

            //Alle Sprechstunden
            var officeHours = db.Activities.OfType <OfficeHour>().ToList();

            var officeHourContract = new List <LecturerOfficeHourContract>();

            foreach (var officeHour in officeHours)
            {
                //Nur buchbaren zukünftige Termine bis gewälten Zeitpunkt
                var nextDate = officeHour.Dates.Where(oc => oc.Begin >= DateTime.Now && oc.Begin <= until && oc.Occurrence.IsAvailable).OrderBy(oc => oc.Begin).ToList();

                if (nextDate != null)
                {
                    foreach (var date in nextDate)
                    {
                        var officehourDate = new LecturerOfficeHourContract();

                        officehourDate.LecturerId = date.Hosts.FirstOrDefault() != null?date.Hosts.First().Id.ToString() : "N.N.";

                        officehourDate.LecturerName = date.Hosts.FirstOrDefault() != null?date.Hosts.First().Name : "N.N.";

                        //Steht der prof beim Raum als Owner drin?
                        officehourDate.LecturerRoomId = date.Rooms.Where(r => r.Owner == officehourDate.LecturerName).FirstOrDefault() != null?date.Hosts.First().Id.ToString() : "N.N.";

                        officehourDate.LecturerRoomNumber = date.Rooms.Where(r => r.Owner == officehourDate.LecturerName).FirstOrDefault() != null?date.Hosts.First().Name : "N.N.";

                        var officehourSlots = new List <LecturerOfficeHourDateSlot>();

                        foreach (var slot in date.Slots)
                        {
                            officehourSlots.Add(new LecturerOfficeHourDateSlot
                            {
                                OfficeHourSlotId            = slot.Id.ToString(),
                                from                        = slot.Begin,
                                until                       = slot.End,
                                NumberOfPossibleSubscribers = slot.Occurrence.Capacity,
                                CurrentNumberOfSubscribers  = slot.Occurrence.Subscriptions.Count(c => c.Id.ToString() != null),
                                isBookablefrom              = slot.Occurrence.FromDateTime,
                                isBookableuntil             = slot.Occurrence.UntilDateTime,
                            });
                        }
                        officehourDate.OfficeHours = officehourSlots;
                        officeHourContract.Add(officehourDate);
                    }
                }
            }

            return(officeHourContract.OrderBy(oh => oh.LecturerName));
        }
Пример #2
0
        /// <summary>
        /// alle zukünftigen Sprechstunden eines Profs
        /// </summary>
        /// <param name="lecturerId"></param>
        /// <param name="until"></param>
        /// <returns></returns>
        public LecturerOfficeHourContract GetLecturerOfficehours(string lecturerId, DateTime until)
        {
            var db = new TimeTableDbContext();

            //nur Sprechstunden des Profs
            var officeHours = db.Activities.OfType <OfficeHour>().Where(oh => oh.Organiser.Id.ToString().Equals(lecturerId)).FirstOrDefault();

            var officehoursContract = new LecturerOfficeHourContract();

            if (officeHours != null)
            {
                var nextDate = officeHours.Dates.Where(oc => oc.Begin >= DateTime.Now && oc.Begin <= until && oc.Occurrence.IsAvailable).OrderBy(oc => oc.Begin).ToList();

                foreach (var date in nextDate)
                {
                    var officehourContract = new LecturerOfficeHourContract();

                    officehourContract.LecturerId = date.Hosts.FirstOrDefault() != null?date.Hosts.First().Id.ToString() : "N.N.";

                    officehourContract.LecturerName = date.Hosts.FirstOrDefault() != null?date.Hosts.First().Name : "N.N.";

                    //Steht der prof beim Raum als Owner drin?
                    officehourContract.LecturerRoomId = date.Rooms.Where(r => r.Owner == officehourContract.LecturerName).FirstOrDefault() != null?date.Hosts.First().Id.ToString() : "N.N.";

                    officehourContract.LecturerRoomNumber = date.Rooms.Where(r => r.Owner == officehourContract.LecturerName).FirstOrDefault() != null?date.Hosts.First().Name : "N.N.";

                    var officehourSlots = new List <LecturerOfficeHourDateSlot>();

                    foreach (var slot in date.Slots)
                    {
                        officehourSlots.Add(new LecturerOfficeHourDateSlot
                        {
                            OfficeHourSlotId            = slot.Id.ToString(),
                            from                        = slot.Begin,
                            until                       = slot.End,
                            NumberOfPossibleSubscribers = slot.Occurrence.Capacity,
                            CurrentNumberOfSubscribers  = slot.Occurrence.Subscriptions.Count(c => c.Id.ToString() != null),
                            isBookablefrom              = slot.Occurrence.FromDateTime,
                            isBookableuntil             = slot.Occurrence.UntilDateTime,
                        });
                    }
                    officehourContract.OfficeHours = officehourSlots;
                    officehoursContract            = officehourContract;
                }
            }
            return(officehoursContract);
        }