コード例 #1
0
        internal OfficeHourDatePreviewModel GetPreviewNextDate(OfficeHour officeHour)
        {
            var model = new OfficeHourDatePreviewModel()
            {
                OfficeHour = officeHour,
            };

            DateTime x = DateTime.Now;

            // nächster Termin => endet in der Zukunft
            var nextDate = officeHour.Dates.Where(d => d.End >= x && d.Occurrence.IsAvailable)
                           .OrderBy(d => d.Begin)
                           .FirstOrDefault();

            model.Date = nextDate;

            if (nextDate == null)
            {
                return(model);
            }

            var date = nextDate;

            model.Subscriptions.AddRange(GetSubscriptions(date));

            return(model);
        }
コード例 #2
0
        private void ProcessOfficeHourData(IDataReader reader, List <OfficeHour> session, Dictionary <int, OfficeHour> book)
        {
            OfficeHour lecture = OfficeHourMap(reader);

            session.Add(lecture);

            book.Add(lecture.Id, lecture);
        }
コード例 #3
0
        /// <summary>
        /// Liste aller Termine aus Sicht eines Users
        /// </summary>
        /// <param name="officeHour"></param>
        /// <param name="userId"></param>
        internal ICollection <OfficeHourDateViewModel> GetDates(OfficeHour officeHour, string userId)
        {
            var allDates = officeHour.Dates.OrderBy(x => x.Begin).ToList();

            var model = new List <OfficeHourDateViewModel>();

            foreach (var date in allDates)
            {
                var dateModel = new OfficeHourDateViewModel();
                dateModel.OfficeHour = officeHour;
                dateModel.Date       = date;

                // Weiche Slots / kein Slots
                if (date.Slots.Any())
                {
                    // bin ich im Slot eingetragen?
                    var slot = date.Slots.FirstOrDefault(x => x.Occurrence.Subscriptions.Any(s => s.UserId.Equals(userId)));
                    if (slot != null)
                    {
                        dateModel.Slot         = slot;
                        dateModel.Subscription = slot.Occurrence.Subscriptions.FirstOrDefault(x => x.UserId.Equals(userId));
                    }
                }
                else
                {
                    dateModel.Subscription = date.Occurrence.Subscriptions.FirstOrDefault(x => x.UserId.Equals(userId));
                }

                // Ergebnisse
                // bin eingetragen (ja/nein) => ist über die Subscription gekennzeichnet
                // darf mich eintragen (ja/nein)
                // Ende der Einschreibeperiode
                dateModel.EndOfSubscriptionPeriod = DateTime.MaxValue;
                if (date.Occurrence.UntilIsRestricted && date.Occurrence.UntilTimeSpan.HasValue)
                {
                    dateModel.EndOfSubscriptionPeriod =
                        date.Begin.AddHours(-date.Occurrence.UntilTimeSpan.Value.Hours)
                        .AddMinutes(-date.Occurrence.UntilTimeSpan.Value.Minutes);
                }



                // ja
                // Liste der verfügbaren Slots bzw. Plätze
                if (date.Slots.Any())
                {
                    dateModel.AvailableSlots.AddRange(date.Slots.Where(x => x.Occurrence.Subscriptions.Count == 0 && x.Occurrence.IsAvailable));
                }
                else
                {
                    dateModel.AvailableSeats = date.Occurrence.Capacity <= 0 ? 1 : date.Occurrence.Capacity - date.Occurrence.Subscriptions.Count;
                }

                model.Add(dateModel);
            }

            return(model);
        }
コード例 #4
0
        //        public async Task<ActionResult> EditOfficeHour([Bind(Include = "UserName,FirstName,LastName,Address1,Address2,City,State,Country,Zip,Phone")] UserProfile userprofile)
        public async Task <ActionResult> EditOfficeHour(OfficeHour officehour)
        {
            if (ModelState.IsValid)
            {
                db.Entry(officehour).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("OfficeHour"));
            }
            return(View(officehour));
        }
コード例 #5
0
        private OfficeHour GetOfficeHour(Assessment assessment)
        {
            var ohName = $"Eignungsgespräche {assessment.Name}";

            var oh = Db.Activities.OfType <OfficeHour>().FirstOrDefault(x => x.Name.Equals(ohName));

            if (oh != null)
            {
                return(oh);
            }

            // Neue Sprechstunde anlegen
            // Alle Kommittee-Mitglieder werden zu Ownern
            oh = new OfficeHour
            {
                Name                = ohName,
                Semester            = assessment.Semester,
                IsInternal          = true,
                FutureSubscriptions = 1,
                Description         = "Eignungsgespräche",
                Organiser           = assessment.Curriculum.Organiser,
                Occurrence          = new Occurrence
                {
                    IsAvailable       = true,
                    Capacity          = 4,
                    FromIsRestricted  = false,
                    UntilIsRestricted = false,
                    UntilTimeSpan     = null,
                    IsCanceled        = false,
                    IsMoved           = false,
                }
            };

            foreach (var committeeMember in assessment.Committee.Members)
            {
                ActivityOwner owner = new ActivityOwner
                {
                    Activity = oh,
                    Member   = committeeMember.Member,
                    IsLocked = false
                };

                oh.Owners.Add(owner);
                Db.ActivityOwners.Add(owner);
            }


            Db.Activities.Add(oh);
            Db.SaveChanges();

            return(oh);
        }
コード例 #6
0
        public OfficeHour Get(int Id)
        {
            OfficeHour         session  = null;
            OfficeHourQuestion question = null;
            Dictionary <int, OfficeHourQuestion> book = new Dictionary <int, OfficeHourQuestion>();
            OfficeHourQuestionTag tag = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.OfficeHours_SelectById"
                                    , inputParamMapper : delegate(SqlParameterCollection paramCollection)
            {
                paramCollection.AddWithValue("@Id", Id);
            }, map : delegate(IDataReader reader, short set)
            {
                if (set == 0)
                {
                    session = OfficeHourMap(reader);
                }
                else if (set == 1)
                {
                    question = OfficeHourQuestionMap(reader);
                    if (session.Questions == null)
                    {
                        session.Questions = new List <OfficeHourQuestion>();
                    }
                    session.Questions.Add(question);

                    book.Add(question.Id, question);
                }
                else if (set == 2)
                {
                    tag = OfficeHourQuestionTagMap(reader);

                    var parent = book[tag.OfficeHourQuestionId];

                    if (parent.Tags == null)
                    {
                        parent.Tags = new List <Tag>();
                    }

                    Tag t     = new Tag();
                    t.Id      = tag.TagId;
                    t.TagName = tag.TagName;
                    parent.Tags.Add(t);
                }
            }
                                    );
            return(session);
        }
コード例 #7
0
        private OfficeHour OfficeHourMap(IDataReader reader)
        {
            OfficeHour item          = new OfficeHour();
            int        startingIndex = 0;

            item.Id           = reader.GetSafeInt32(startingIndex++);
            item.InstructorId = reader.GetSafeInt32(startingIndex++);
            item.Date         = reader.GetSafeDateTime(startingIndex++);
            item.StartTime    = reader.GetSafeInt32(startingIndex++);
            item.EndTime      = reader.GetSafeInt32(startingIndex++);
            item.TimeZone     = reader.GetSafeInt32(startingIndex++);
            item.Topic        = reader.GetSafeString(startingIndex++);
            item.Instructions = reader.GetSafeString(startingIndex++);
            item.SectionId    = reader.GetSafeInt32(startingIndex++);

            return(item);
        }
コード例 #8
0
        public static string GetDescriptionText(this OfficeHour officeHour)
        {
            var stringBuilder = new StringBuilder();
            var languageFile  = App.Instance.AppState.LanguageFile;

            var dayOfWeek = languageFile.TranslateDayOfWeek(officeHour.DayOfWeek);
            var hourFrom  = officeHour.From.ToString(CultureInfo.InvariantCulture);
            var to        = officeHour.To.ToString(CultureInfo.InvariantCulture);

            stringBuilder.AppendLine(dayOfWeek);
            stringBuilder.AppendLine(hourFrom);
            stringBuilder.AppendLine(to);

            var result = stringBuilder.ToString();

            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Liste aller Termine aus Sicht eines Users
        /// </summary>
        /// <param name="officeHour"></param>
        internal ICollection <OfficeHourDateViewModel> GetDates(OfficeHour officeHour)
        {
            var allDates = officeHour.Dates.OrderBy(x => x.Begin).ToList();

            var model = new List <OfficeHourDateViewModel>();
            var now   = DateTime.Now;

            foreach (var date in allDates)
            {
                var dateModel = new OfficeHourDateViewModel();
                dateModel.OfficeHour = officeHour;
                dateModel.Date       = date;

                // Ende der Einschreibeperiode
                dateModel.EndOfSubscriptionPeriod = DateTime.MaxValue;
                if (date.Occurrence.UntilIsRestricted && date.Occurrence.UntilTimeSpan.HasValue)
                {
                    dateModel.EndOfSubscriptionPeriod =
                        date.Begin.AddHours(-date.Occurrence.UntilTimeSpan.Value.Hours)
                        .AddMinutes(-date.Occurrence.UntilTimeSpan.Value.Minutes);
                }

                // ja
                // Liste der verfügbaren Slots bzw. Plätze
                if (date.Slots.Any())
                {
                    dateModel.AvailableSlots.AddRange(date.Slots.Where(x => x.Occurrence.Subscriptions.Count == 0 && x.Occurrence.IsAvailable));

                    foreach (var slot in date.Slots)
                    {
                        dateModel.Subscriptions.AddRange(slot.Occurrence.Subscriptions);
                    }
                }
                else
                {
                    dateModel.AvailableSeats = date.Occurrence.Capacity <= 0 ? 1 : date.Occurrence.Capacity - date.Occurrence.Subscriptions.Count;
                    dateModel.Subscriptions.AddRange(date.Occurrence.Subscriptions);
                }

                model.Add(dateModel);
            }

            return(model);
        }
コード例 #10
0
        private static void ParseTime(OfficeHour officeHour, string s)
        {
            s = s.Replace(" ", "");
            var split = s.Split('-');
            var from  = split[0];
            var to    = split[1];

            var hourFrom   = Convert.ToInt32(@from.Split(':')[0]);
            var minuteFrom = Convert.ToInt32(@from.Split(':')[1]);

            var hourTo   = Convert.ToInt32(to.Split(':')[0]);
            var minuteTo = Convert.ToInt32(to.Split(':')[1]);

            var fromTime = new DateTime(1970, 1, 1, hourFrom, minuteFrom, 0);
            var toTime   = new DateTime(1970, 1, 1, hourTo, minuteTo, 0);

            officeHour.From = fromTime;
            officeHour.To   = toTime;
        }
コード例 #11
0
        internal OfficeHourDateViewModel GetNextSubscription(OfficeHour officeHour, string userId)
        {
            OfficeHourDateViewModel ohm = new OfficeHourDateViewModel();
            DateTime x = DateTime.Now;

            // das nächste Datum
            var nextDate = officeHour.Dates.Where(d =>
                                                  d.Begin >= x &&                                                                         // in der Zukunft
                                                  (d.Occurrence.Subscriptions.Any(s => s.UserId.Equals(userId)) ||                        // im Date eingeschrieben
                                                   d.Slots.Any(slot => slot.Occurrence.Subscriptions.Any(s => s.UserId.Equals(userId))))) // in irgendeinem Slot eingeschrieben
                           .OrderBy(d => d.Begin)
                           .FirstOrDefault();

            if (nextDate != null)
            {
                ohm.Date     = nextDate;
                ohm.Lecturer = nextDate.Hosts.FirstOrDefault();

                // noch schauen, ob es eine Eintragung in einem Slot ist
                var nextSlot =
                    nextDate.Slots.Where(slot =>
                                         slot.Occurrence.Subscriptions.Any(s => s.UserId.Equals(userId)))
                    .OrderBy(d => d.Begin)
                    .FirstOrDefault();

                ohm.Slot = nextSlot;
            }
            else
            {
                var firstDate = officeHour.Dates.FirstOrDefault();
                if (firstDate != null)
                {
                    ohm.Lecturer = firstDate.Hosts.FirstOrDefault();
                }
            }


            ohm.OfficeHour = officeHour;


            return(ohm);
        }
コード例 #12
0
        public List <OfficeHour> GetByDate()
        {
            List <OfficeHour> list = null;

            DataProvider.ExecuteCmd(GetConnection, "dbo.OfficeHours_SelectAllBYDate"
                                    , inputParamMapper : null,
                                    map : delegate(IDataReader reader, short set)
            {
                OfficeHour item = OfficeHourMap(reader);

                if (list == null)
                {
                    list = new List <OfficeHour>();
                }

                list.Add(item);
            }
                                    );
            return(list);
        }
コード例 #13
0
 private static IEnumerable <OfficeHour> ParseOfficeHoursFromTable(HtmlElement[] tableTRs)
 {
     for (int i = 0; i < tableTRs.Length; i++)
     {
         if (string.IsNullOrWhiteSpace(tableTRs[i].InnerText))
         {
             continue;
         }
         DayOfWeek?dayOfWeek = ParseDayOfWeek(tableTRs[i].Children[0]?.InnerText?.ToLower().Trim() ?? "");
         if (!dayOfWeek.HasValue)
         {
             continue;
         }
         Debug.Assert(tableTRs[i].Children.Count > 1);
         foreach (HtmlElement child in tableTRs[i].Children.OfType <HtmlElement>().Skip(1))
         {
             Debug.Assert(!string.IsNullOrWhiteSpace(child.InnerText));
             if (child.Children.Count == 0)
             {
                 var officeHour = new OfficeHour {
                     DayOfWeek = dayOfWeek.Value
                 };
                 ParseTime(officeHour, child.InnerText);
                 yield return(officeHour);
             }
             else
             {
                 var children = child.Children[0].Children[0].Children[0].Children.OfType <HtmlElement>().ToArray();
                 foreach (var timeChild in children)
                 {
                     var officeHour = new OfficeHour {
                         DayOfWeek = dayOfWeek.Value
                     };
                     ParseTime(officeHour, timeChild.InnerText);
                     yield return(officeHour);
                 }
             }
         }
     }
 }
コード例 #14
0
 /// <summary>
 /// Liefert alle Eintragungen eines Users in einer Sprechstunde
 /// </summary>
 /// <param name="officeHour"></param>
 /// <param name="userId"></param>
 internal void GetSubscriptions(OfficeHour officeHour, string userId)
 {
 }
コード例 #15
0
        public OfficeHour CreateOfficeHour(OfficeHourCreateRequest request)
        {
            var db = new TimeTableDbContext();

            var organizer = db.Organisers.SingleOrDefault(o => o.Id == request.OrgId);

            if (organizer == null)
            {
                return(null);
            }

            var lecturer = organizer.Members.SingleOrDefault(l => l.Id == request.DozId);

            if (lecturer == null)
            {
                return(null);
            }

            var semester = db.Semesters.SingleOrDefault(s => s.Id == request.SemesterId);

            var officeHour = db.Activities.OfType <OfficeHour>()
                             .SingleOrDefault(oh => oh.Semester.Id == semester.Id &&
                                              oh.Dates.Any(oc => oc.Hosts.Any(l => l.Id == lecturer.Id)));

            if (officeHour == null)
            {
                officeHour = new OfficeHour
                {
                    Name                = "Sprechstunde",
                    ShortName           = lecturer.ShortName,
                    ByAgreement         = request.ByAgreement,
                    Description         = request.Text,
                    Organiser           = organizer,
                    Semester            = semester,
                    SlotsPerDate        = request.SlotsPerDate,
                    FutureSubscriptions = request.FutureSlots,
                    Occurrence          = new Occurrence
                    {
                        IsAvailable       = true,
                        Capacity          = request.SlotDuration > 0 ? -1 : request.Capacity,
                        FromIsRestricted  = false,
                        UntilIsRestricted = (request.SubscriptionLimit > 0),
                        UntilTimeSpan     =
                            (request.SubscriptionLimit > 0)
                                ? new TimeSpan(request.SubscriptionLimit - 1, 59, 0)
                                : new TimeSpan?(),
                        IsCanceled = false,
                        IsMoved    = false,
                    }
                };

                // den Anbieter als Owner eintragen, aber nur wenn er noch nicht drin ist
                if (officeHour.Owners.All(x => x.Member.Id != lecturer.Id))
                {
                    ActivityOwner owner = new ActivityOwner
                    {
                        Activity = officeHour,
                        Member   = lecturer,
                        IsLocked = false
                    };

                    officeHour.Owners.Add(owner);
                    db.ActivityOwners.Add(owner);
                }


                db.Activities.Add(officeHour);
                db.SaveChanges();
            }

            if (request.CreateDates)
            {
                var semesterService = new SemesterService();
                var dates           = semesterService.GetDays(request.SemesterId, request.DayOfWeek, semester.StartCourses, request.LastDate);

                foreach (var dateTime in dates)
                {
                    var ocStart = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, request.StartTime.Hours,
                                               request.StartTime.Minutes, request.StartTime.Seconds);
                    var ocEnd = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, request.EndTime.Hours,
                                             request.EndTime.Minutes, request.EndTime.Seconds);

                    var occurrence = new ActivityDate
                    {
                        Begin    = ocStart,
                        End      = ocEnd,
                        Activity = officeHour,
                        Hosts    = new HashSet <OrganiserMember>
                        {
                            lecturer,
                        },
                        Occurrence = new Occurrence
                        {
                            IsAvailable       = true,
                            Capacity          = request.SlotDuration > 0 ? -1 : request.Capacity,
                            FromIsRestricted  = false,
                            UntilIsRestricted = (request.SubscriptionLimit > 0),
                            UntilTimeSpan     =
                                (request.SubscriptionLimit > 0)
                                    ? new TimeSpan(request.SubscriptionLimit - 1, 59, 0)
                                    : new TimeSpan?(),
                            IsCanceled = false,
                            IsMoved    = false,
                        }
                    };

                    // Slots
                    if (request.SlotDuration > 0)
                    {
                        var ohDuration = request.EndTime - request.StartTime;

                        var numSlots = (int)(ohDuration.TotalMinutes / request.SlotDuration + 0.01);


                        for (int i = 1; i <= numSlots; i++)
                        {
                            var slotStart = ocStart.AddMinutes((i - 1) * request.SlotDuration);
                            var slotEnd   = ocStart.AddMinutes(i * request.SlotDuration);

                            // i-ter Slot
                            var available = true;
                            if (request.SpareSlots == -99)
                            {
                                available = (i > 1 && i < numSlots);
                            }
                            else
                            {
                                if (request.SpareSlots < 0) // Anzahl vom Ende her
                                {
                                    available = (i <= numSlots + request.SpareSlots);
                                }
                                else if (request.SpareSlots > 0) // Anzahl vom Anfang
                                {
                                    available = (i > request.SpareSlots);
                                }
                            }


                            var slot = new ActivitySlot
                            {
                                Begin      = slotStart,
                                End        = slotEnd,
                                Occurrence = new Occurrence
                                {
                                    IsAvailable       = available,
                                    Capacity          = request.Capacity,
                                    FromIsRestricted  = false, // Zeitrestriktionen nur auf dem Activity Date
                                    UntilIsRestricted = false,
                                    IsCanceled        = false,
                                    IsMoved           = false,
                                }
                            };

                            occurrence.Slots.Add(slot);
                        }
                    }

                    officeHour.Dates.Add(occurrence);
                }

                db.SaveChanges();
            }

            return(officeHour);
        }
コード例 #16
0
 internal OrganiserMember GetHost(OfficeHour officeHour)
 {
     return(officeHour.Owners.First().Member);
 }
コード例 #17
0
        private OfficeHour OfficeHourMap(IDataReader reader)
        {
            OfficeHour item = new OfficeHour();
            int startingIndex = 0;

            item.Id = reader.GetSafeInt32(startingIndex++);
            item.InstructorId = reader.GetSafeInt32(startingIndex++);
            item.Date = reader.GetSafeDateTime(startingIndex++);
            item.StartTime = reader.GetSafeInt32(startingIndex++);
            item.EndTime = reader.GetSafeInt32(startingIndex++);
            item.TimeZone = reader.GetSafeInt32(startingIndex++);
            item.Topic = reader.GetSafeString(startingIndex++);
            item.Instructions = reader.GetSafeString(startingIndex++);
            item.SectionId = reader.GetSafeInt32(startingIndex++);

            return item;
        }