コード例 #1
0
        public LmsCourseMeeting GetLtiCreatedByCompanyAndScoId(ILmsLicense lmsCompany, string scoId)
        {
            if (lmsCompany == null)
            {
                throw new ArgumentNullException(nameof(lmsCompany));
            }
            if (string.IsNullOrWhiteSpace(scoId))
            {
                throw new ArgumentException("scoId can not be empty", nameof(scoId));
            }

            // NOTE: check only licenses of the company with the same AC!!
            var query = from c in this.Repository.Session.Query <LmsCompany>()
                        where c.CompanyId == lmsCompany.CompanyId
                        select new { c.Id, c.AcServer };
            var currentLicenseAc = new Uri(lmsCompany.AcServer);
            var companyLicenses  = query.ToArray().Where(c => new Uri(c.AcServer).Host == currentLicenseAc.Host).Select(c => c.Id).ToArray();

            // NOTE: return only not-reused meeting - created from LTI
            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            var defaultQuery    = new DefaultQueryOver <LmsCourseMeeting, int>()
                                  .GetQueryOver(() => x)
                                  .JoinAlias(() => x.OfficeHours, () => oh, JoinType.LeftOuterJoin)
                                  //.Clone()
                                  .WhereRestrictionOn(() => x.LmsCompanyId).IsIn(companyLicenses)
                                  .Where(() =>
                                         (x.Reused == null || x.Reused == false)
                                         &&
                                         (((x.ScoId != null) && (x.ScoId == scoId)) ||
                                          (x.OfficeHours != null && oh.ScoId == scoId)))
                                  .Take(1);

            return(this.Repository.FindOne(defaultQuery).Value);
        }
コード例 #2
0
        private QueryOver <LmsCourseMeeting, LmsCourseMeeting> GetByCompanyAndScoIdQuery(ILmsLicense lmsCompany, string scoId, int excludedLmsCourseMeetingId)
        {
            if (lmsCompany == null)
            {
                throw new ArgumentNullException(nameof(lmsCompany));
            }
            if (string.IsNullOrWhiteSpace(scoId))
            {
                throw new ArgumentException("scoId can not be empty", nameof(scoId));
            }

            // NOTE: check only licenses of the company with the same AC!!
            var query = from c in this.Repository.Session.Query <LmsCompany>()
                        where c.CompanyId == lmsCompany.CompanyId
                        select new { c.Id, c.AcServer };
            var currentLicenseAc = new Uri(lmsCompany.AcServer);
            var companyLicenses  = query.ToArray().Where(c => new Uri(c.AcServer).Host == currentLicenseAc.Host).Select(c => c.Id).ToArray();

            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            QueryOver <LmsCourseMeeting, LmsCourseMeeting> defaultQuery = new DefaultQueryOver <LmsCourseMeeting, int>()
                                                                          .GetQueryOver(() => x)
                                                                          .JoinAlias(() => x.OfficeHours, () => oh, JoinType.LeftOuterJoin)
                                                                          .WhereRestrictionOn(() => x.LmsCompanyId).IsIn(companyLicenses)
                                                                          .And(() => x.Id != excludedLmsCourseMeetingId)
                                                                          .And(() =>
                                                                               ((x.ScoId != null) && (x.ScoId == scoId)) ||
                                                                               (x.OfficeHours != null && oh.ScoId == scoId))
                                                                          .TransformUsing(Transformers.DistinctRootEntity);

            return(defaultQuery);
        }
コード例 #3
0
        public List <LmsCompany> GetEnabledForSynchronization(string consumerKey = null)
        {
            LmsCompany               lc  = null;
            LmsCompanySetting        lcs = null;
            OfficeHours              oh  = null;
            IList <LmsCourseMeeting> lcm = null;
            //IList<LmsUserMeetingRole> lumr = null;
            //IList<LmsUser> lu = null;
            //LmsUser u = null;
            var defaultQuery = new DefaultQueryOver <LmsCompany, int>()
                               .GetQueryOver(() => lc)
                               .Where(x => x.IsActive);

            if (!string.IsNullOrEmpty(consumerKey))
            {
                defaultQuery = defaultQuery.Where(x => x.ConsumerKey == consumerKey);
            }
            defaultQuery = defaultQuery
                           .JoinAlias(() => lc.Settings, () => lcs)
                           .Where(() => lcs.Name == LmsLicenseSettingNames.UseSynchronizedUsers && lcs.Value == "True")
                           .JoinAlias(() => lc.LmsCourseMeetings, () => lcm)
                           .JoinAlias(() => lcm.First().OfficeHours, () => oh, JoinType.LeftOuterJoin)
//                .JoinAlias(() => lcm.First().MeetingRoles, () => lumr)
//                .Fetch(x => x.Settings).Eager
                           .Fetch(x => x.LmsCourseMeetings).Eager
                           .Fetch(x => x.LmsCourseMeetings.First().OfficeHours).Eager
//                .Fetch(x => x.LmsCourseMeetings.First().MeetingRoles).Eager
                           .Fetch(x => x.AdminUser).Eager
                           .TransformUsing(Transformers.DistinctRootEntity);
            return(this.Repository.FindAll(defaultQuery).ToList());
        }
コード例 #4
0
        public IFutureValue <LmsCourseMeeting> GetOneByUserAndType(int companyLmsId, string userId, LmsMeetingType type)
        {
            if (companyLmsId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(companyLmsId));
            }
            if (string.IsNullOrWhiteSpace(userId))
            {
                throw new ArgumentException("userId can not be empty", nameof(userId));
            }
            if (type <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(type));
            }

            int typeValue       = (int)type;
            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            LmsUser          u  = null;
            var defaultQuery    = new DefaultQueryOver <LmsCourseMeeting, int>()
                                  .GetQueryOver(() => x)
                                  .JoinAlias(() => x.OfficeHours, () => oh, JoinType.InnerJoin)
                                  .JoinAlias(() => oh.LmsUser, () => u, JoinType.InnerJoin)
                                  .Where(() => x.LmsCompanyId == companyLmsId &&
                                         x.LmsMeetingType == typeValue &&
                                         (x.OfficeHours != null && u.UserId == userId))
                                  .Take(1);

            return(this.Repository.FindOne(defaultQuery));
        }
コード例 #5
0
 protected override Church Parse()
 {
     return(new Church
     {
         Id = ToInt(SimbahanID),
         StreetNumber = ToInt(StreetNo),
         StreetName = StreetName.ToString(),
         Barangay = Barangay.ToString(),
         StateProvince = StateOrProvince.ToString(),
         City = City.ToString(),
         ZipCode = ZipCode.ToString(),
         CompleteAddress = CompleteAddress.ToString(),
         Diocese = Diocese.ToString(),
         Parish = Parish.ToString(),
         Priest = ParishPriest.ToString(),
         Vicariate = Vicariate.ToString(),
         DateEstablished = DateEstablished.ToString(),
         LastUpdate = ToDateTime(LastUpdate),
         FeastDay = FeastDay.ToString(),
         ContactNo = ContactNo.ToString(),
         Latitude = ToDouble(Latitude),
         Longitude = ToDouble(Longitude),
         HasAdorationChapel = ToBoolean(HasAdorationChapel),
         ChurchHistory = ChurchHistory.ToString(),
         OfficeHours = OfficeHours.ToString(),
         ChurchTypeId = ToInt(ChurchTypeID),
         Website = Website.ToString(),
         EmailAddress = EmailAddress.ToString(),
         DevotionSchedule = DevotionSchedule.ToString(),
         LocationId = ToInt(LocationID),
         ChurchCode = ChurchCode.ToString()
     });
 }
コード例 #6
0
ファイル: DataManager.cs プロジェクト: David-Jing/PathFinder
    public IEnumerator OfficeHours()
    {
        OfficeHours SQL_OH  = new OfficeHours();
        JSONNode    JSON_OH = JSONReader.Read("GetOfficeHours");

        for (int i = 0; i < JSON_OH.Count; i++)
        {
            SQL_OH.CoursesOffered_ID = JSON_OH[i]["courses_offered_id"] != "null" ?
                                       int.Parse(JSON_OH[i]["courses_offered_id"]) : 0;
            SQL_OH.StakeHolder_ID = JSON_OH[i]["stakeholder_id"] != "null" ?
                                    int.Parse(JSON_OH[i]["stakeholder_id"]) : 0;

            SQL_OH.LastName           = JSON_OH[i]["LastName"];
            SQL_OH.FirstName          = JSON_OH[i]["FirstName"];
            SQL_OH.PreferredFirstName = JSON_OH[i]["PreferredFirstName"];
            SQL_OH.Section            = JSON_OH[i]["Section"];
            SQL_OH.Location           = JSON_OH[i]["Location"];
            SQL_OH.Subject            = JSON_OH[i]["Subject"];
            SQL_OH.CourseNumber       = JSON_OH[i]["CourseNumber"];
            SQL_OH.TermDisplay        = JSON_OH[i]["TermDisplay"];
            SQL_OH.StartTime          = JSON_OH[i]["StartTime"];
            SQL_OH.EndTime            = JSON_OH[i]["EndTime"];
            SQL_OH.Room           = JSON_OH[i]["Room"];
            SQL_OH.Day            = JSON_OH[i]["Day"];
            SQL_OH.OfficeLocation = JSON_OH[i]["OfficeLocation"];

            dbLink.Insert(SQL_OH);
        }

        yield break;
    }
コード例 #7
0
        public IEnumerable <LmsCourseMeeting> GetByCompanyWithAudioProfiles(ILmsLicense lmsCompany)
        {
            if (lmsCompany == null)
            {
                throw new ArgumentNullException(nameof(lmsCompany));
            }

            // NOTE: check only licenses of the company with the same AC!!
            var query = from c in this.Repository.Session.Query <LmsCompany>()
                        where c.CompanyId == lmsCompany.CompanyId
                        select new { c.Id, c.AcServer };
            var currentLicenseAc = new Uri(lmsCompany.AcServer);
            var companyLicenses  = query.ToArray().Where(c => new Uri(c.AcServer).Host == currentLicenseAc.Host).Select(c => c.Id).ToArray();

            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            var defaultQuery    = new DefaultQueryOver <LmsCourseMeeting, int>()
                                  .GetQueryOver(() => x)
                                  .JoinAlias(() => x.OfficeHours, () => oh, JoinType.LeftOuterJoin)
                                  .WhereRestrictionOn(() => x.LmsCompanyId).IsIn(companyLicenses)
                                  .And(() => x.AudioProfileId != null)
                                  .TransformUsing(Transformers.DistinctRootEntity);

            return(this.Repository.FindAll(defaultQuery));
        }
コード例 #8
0
        public static List <OfficeHours> GetOfficeHours(this SqlDataReader reader)
        {
            EuropeanDayOfWeek? nullable;
            EuropeanDayOfWeek? nullable1;
            EuropeanDayOfWeek? nullable2;
            List <OfficeHours> officeHours = new List <OfficeHours>();

            while (reader.Read())
            {
                bool?isActive = reader.GetNullableValue <bool>("IsActive");
                if (!isActive.HasValue || !isActive.Value)
                {
                    continue;
                }
                OfficeHours item = new OfficeHours()
                {
                    Id = reader.GetNullableValue <long>("OfficeHoursId")
                };
                OfficeHours officeHour    = item;
                int?        nullableValue = reader.GetNullableValue <int>("DayOfWeekId");
                if (nullableValue.HasValue)
                {
                    nullable1 = new EuropeanDayOfWeek?((EuropeanDayOfWeek)nullableValue.GetValueOrDefault());
                }
                else
                {
                    nullable  = null;
                    nullable1 = nullable;
                }
                officeHour.StartDay = nullable1;
                OfficeHours officeHour1 = item;
                nullableValue = reader.GetNullableValue <int>("DayOfWeekId");
                if (nullableValue.HasValue)
                {
                    nullable2 = new EuropeanDayOfWeek?((EuropeanDayOfWeek)nullableValue.GetValueOrDefault());
                }
                else
                {
                    nullable  = null;
                    nullable2 = nullable;
                }
                officeHour1.EndDay = nullable2;
                DateTime?startTime = reader.GetNullableValue <DateTime>("StartTime");
                if (startTime.HasValue)
                {
                    item.StartTime = new DateTime?(startTime.Value);
                }
                DateTime?endTime = reader.GetNullableValue <DateTime>("EndTime");
                if (endTime.HasValue)
                {
                    item.EndTime = new DateTime?(endTime.Value);
                }
                item.Note = reader["Note"].ToString();
                officeHours.Add(item);
            }
            return(DataReaderHelper.NormalizeOfficeHours(officeHours));
        }
コード例 #9
0
 public OfficeHoursVm(OfficeHours officeHours)
 {
     this.Id        = officeHours.Id;
     this.StartDay  = officeHours.StartDay;
     this.EndDay    = officeHours.EndDay;
     this.StartTime = officeHours.StartTime;
     this.EndTime   = officeHours.EndTime;
     this.Note      = officeHours.Note;
 }
コード例 #10
0
ファイル: TestScheduler.cs プロジェクト: aby1990/MeetingApp
        public void ValidateIsMeetInOfficeHours()
        {
            Meetup newMeet = new Meetup {
                MeetupStart = new DateTime(2011, 03, 21, 16, 00, 0), MeetupEnd = new DateTime(2011, 03, 21, 17, 0, 0), EntityName = "EMP001"
            };
            OfficeHours offHours = new OfficeHours {
                StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(17, 30, 0)
            };

            Assert.Equal(_planMeetup.ValidateOfficeTimeLimits(newMeet, offHours), true);
        }
コード例 #11
0
ファイル: TestScheduler.cs プロジェクト: aby1990/MeetingApp
        public void ValidateGetOfficeHours()
        {
            string      inp      = "0900 1730";
            OfficeHours meet     = _planMeetup.GetOfficeHours(inp);
            OfficeHours expected = new OfficeHours {
                StartTime = new TimeSpan(9, 0, 0), EndTime = new TimeSpan(17, 30, 0)
            };
            var obj1Str = JsonConvert.SerializeObject(meet);
            var obj2Str = JsonConvert.SerializeObject(expected);

            Assert.Equal(obj1Str, obj2Str);
        }
コード例 #12
0
        public IEnumerable <OfficeHoursTeacherAvailability> GetAvailabilities(int ohId)
        {
            OfficeHoursTeacherAvailability x = null;
            OfficeHours oh           = null;
            LmsUser     u            = null;
            var         defaultQuery = new DefaultQueryOver <OfficeHoursTeacherAvailability, int>()
                                       .GetQueryOver(() => x)
                                       .JoinAlias(() => x.Meeting, () => oh, JoinType.InnerJoin)
                                       .JoinAlias(() => x.User, () => u, JoinType.InnerJoin)
                                       .Where(() => x.Meeting.Id == ohId);

            return(Repository.FindAll(defaultQuery));
        }
コード例 #13
0
ファイル: Office.cs プロジェクト: EikeStein/PsychoSearch
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (Address != null ? Address.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (TelefoneNumbers != null ? TelefoneNumbers.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (OfficeHours != null ? OfficeHours.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (ContactTimes != null ? ContactTimes.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (Location != null ? Location.GetHashCode() : 0);
         return(hashCode);
     }
 }
コード例 #14
0
        public OfficeHoursSlot GetSlotForDate(DateTime start, int ohId)
        {
            OfficeHoursTeacherAvailability availability = null;
            OfficeHoursSlot x            = null;
            OfficeHours     oh           = null;
            LmsUser         u            = null;
            var             defaultQuery = new DefaultQueryOver <OfficeHoursSlot, int>()
                                           .GetQueryOver(() => x)
                                           .JoinAlias(() => x.User, () => u, JoinType.InnerJoin)
                                           .JoinAlias(() => x.Availability, () => availability, JoinType.InnerJoin)
                                           .JoinAlias(() => availability.Meeting, () => oh, JoinType.InnerJoin)
                                           .Where(() => x.Start == start && oh.Id == ohId);

            return(Repository.FindOne(defaultQuery).Value);
        }
コード例 #15
0
        public IEnumerable <OfficeHoursSlot> GetSlotsForDate(DateTime start, DateTime end, int ohId)
        {
            OfficeHoursTeacherAvailability availability = null;
            OfficeHoursSlot x            = null;
            OfficeHours     oh           = null;
            LmsUser         u            = null;
            var             defaultQuery = new DefaultQueryOver <OfficeHoursSlot, int>()
                                           .GetQueryOver(() => x)
                                           .JoinAlias(() => x.User, () => u, JoinType.InnerJoin)
                                           .JoinAlias(() => x.Availability, () => availability, JoinType.InnerJoin)
                                           .JoinAlias(() => availability.Meeting, () => oh, JoinType.InnerJoin)
                                           .Where(() => x.Start >= start && x.Start < end && oh.Id == ohId);

            return(Repository.FindAll(defaultQuery));
        }
コード例 #16
0
        public async Task <IEnumerable <SlotDto> > ValidateSlotsRange(OfficeHours oh, int lmsUserId,
                                                                      OfficeHoursTeacherAvailabilityDto availabilityDto)
        {
            var currentSlots = await GetSlots(oh.Id, lmsUserId, DateTime.UtcNow, DateTime.UtcNow.AddYears(1));

            var slotsToCheck =
                GetSlotsForAvailability(availabilityDto, DateTime.UtcNow, DateTime.UtcNow.AddYears(1), lmsUserId, null);
            var overlappingSlots = currentSlots.Where(cs =>
                                                      slotsToCheck.Any(
                                                          x => (cs.Start <= x.Start && cs.End > x.Start) || (cs.Start < x.End && cs.End >= x.End)));

            //slotsToCheck.Any(x => currentSlots.Any(cs => (checkEmptySlots || cs.Status != 0) && ((cs.Start<= x.Start && cs.End > x.Start) || (cs.Start < x.End && cs.End >= x.End)))))
            //return false;
            return(overlappingSlots);
        }
コード例 #17
0
        private static OfficeHoursTeacherAvailability ConvertFromDto(OfficeHours oh, LmsUser lmsUser, OfficeHoursTeacherAvailabilityDto availabilityDto)
        {
            var entity = new OfficeHoursTeacherAvailability
            {
                User        = lmsUser,
                Duration    = availabilityDto.Duration,
                Intervals   = string.Join(",", availabilityDto.Intervals.Select(x => $"{x.Start}-{x.End}")),
                DaysOfWeek  = string.Join(",", availabilityDto.DaysOfWeek),
                PeriodStart = availabilityDto.PeriodStart,
                PeriodEnd   = availabilityDto.PeriodEnd,
                Meeting     = oh
            };

            return(entity);
        }
コード例 #18
0
        public IEnumerable <LmsCourseMeeting> GetAllByOfficeHoursId(int officeHoursId)
        {
            if (officeHoursId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(officeHoursId));
            }

            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            var defaultQuery    = new DefaultQueryOver <LmsCourseMeeting, int>()
                                  .GetQueryOver(() => x)
                                  .JoinAlias(() => x.OfficeHours, () => oh, JoinType.LeftOuterJoin)
                                  .Where(() => x.OfficeHours != null && oh.Id == officeHoursId);

            return(this.Repository.FindAll(defaultQuery));
        }
コード例 #19
0
        /// <summary>
        /// The get all by meeting id.
        /// </summary>
        /// <param name="meetingId">
        /// The meeting id.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{LmsCourseMeeting}"/>.
        /// </returns>
        public IEnumerable <LmsCourseMeeting> GetAllByMeetingId(string meetingScoId)
        {
            if (string.IsNullOrWhiteSpace(meetingScoId))
            {
                throw new ArgumentException("meetingId can not be empty", nameof(meetingScoId));
            }

            LmsCourseMeeting x  = null;
            OfficeHours      oh = null;
            var defaultQuery    = new DefaultQueryOver <LmsCourseMeeting, int>()
                                  .GetQueryOver(() => x)
                                  .JoinAlias(() => x.OfficeHours, () => oh, JoinType.LeftOuterJoin)
                                  .Where(() => (((x.ScoId != null) && (x.ScoId == meetingScoId)) ||
                                                (x.OfficeHours != null && oh.ScoId == meetingScoId)));

            return(this.Repository.FindAll(defaultQuery));
        }
コード例 #20
0
        public List <OfficeHoursVm> GetOfficeHours(string practiceLocationId)
        {
            List <OfficeHoursVm> result = this.CreateEmptyViewModel(practiceLocationId);
            var manager            = new OfficeHoursIt2Manager();
            var helper             = new Helper();
            List <OfficeHours> tmp = manager.GetOfficeHours(practiceLocationId);

            foreach (OfficeHoursVm item in result)
            {
                OfficeHours a = tmp.Find(x => x.OperatingDay.ToString() == item.OperatingDay);
                if (a == null)
                {
                    continue;
                }

                item.Id = a.Id;
                item.PracticeLocationId = a.PracticeLocationId;
                item.IsOperatingDay     = true;
                if (a.OpenFrom == null)
                {
                    continue;
                }

                string[] d = helper.IntegerToTimeDisplay((int)a.OpenFrom);
                item.OpenFrom     = d[0];
                item.OpenFromAmPm = d[1];

                if (a.OpenTo == null)
                {
                    continue;
                }

                string[] dd = helper.IntegerToTimeDisplay((int)a.OpenTo);
                item.OpenTo     = dd[0];
                item.OpenToAmPm = dd[1];
            }

            return(result);
        }
コード例 #21
0
        public static List <OfficeHours> NormalizeOfficeHours(List <OfficeHours> officeHours)
        {
            if (!officeHours.Any())
            {
                return(officeHours);
            }
            List <OfficeHours> newList = new List <OfficeHours>();
            OfficeHours        newItem = officeHours.First();

            for (int i = 1; i < officeHours.Count; i++)
            {
                bool isEqualNotes = (string.IsNullOrWhiteSpace(newItem.Note) && string.IsNullOrWhiteSpace(officeHours[i].Note)) || (!string.IsNullOrWhiteSpace(newItem.Note) && !string.IsNullOrWhiteSpace(officeHours[i].Note) && newItem.Note.Equals(officeHours[i].Note));
                if (newItem.StartTime == officeHours[i].StartTime && newItem.EndTime == officeHours[i].EndTime && isEqualNotes && newItem.EndDay + 1 == officeHours[i].EndDay)
                {
                    newItem.EndDay = officeHours[i].EndDay;
                    continue;
                }
                newList.Add(newItem);
                newItem = officeHours[i];
            }
            newList.Add(newItem);
            return(newList);
        }
コード例 #22
0
        private static List <OfficeHours> NormalizeOfficeHours(List <OfficeHours> officeHours)
        {
            if (!officeHours.Any())
            {
                return(officeHours);
            }
            List <OfficeHours> list         = new List <OfficeHours>();
            OfficeHours        officeHours2 = officeHours.First();

            for (int i = 1; i < officeHours.Count; i++)
            {
                bool flag = (string.IsNullOrWhiteSpace(officeHours2.Note) && string.IsNullOrWhiteSpace(officeHours[i].Note)) || (!string.IsNullOrWhiteSpace(officeHours2.Note) && !string.IsNullOrWhiteSpace(officeHours[i].Note) && officeHours2.Note.Equals(officeHours[i].Note));
                if (officeHours2.StartTime == officeHours[i].StartTime && officeHours2.EndTime == officeHours[i].EndTime && flag && officeHours2.EndDay + 1 == officeHours[i].EndDay)
                {
                    officeHours2.EndDay = officeHours[i].EndDay;
                    continue;
                }
                list.Add(officeHours2);
                officeHours2 = officeHours[i];
            }
            list.Add(officeHours2);
            return(list);
        }
コード例 #23
0
        public static List <OfficeHours> GetOfficeHours(this SqlDataReader reader)
        {
            List <OfficeHours> list = new List <OfficeHours>();

            while (reader.Read())
            {
                OfficeHours officeHours = new OfficeHours();
                officeHours.StartDay = (EuropeanDayOfWeek?)reader.GetNullableValue <int>("DayOfWeekId");
                officeHours.EndDay   = (EuropeanDayOfWeek?)reader.GetNullableValue <int>("DayOfWeekId");
                DateTime?nullableValue = reader.GetNullableValue <DateTime>("StartTime");
                if (nullableValue.HasValue)
                {
                    officeHours.StartTime = nullableValue.Value;
                }
                DateTime?nullableValue2 = reader.GetNullableValue <DateTime>("EndTime");
                if (nullableValue2.HasValue)
                {
                    officeHours.EndTime = nullableValue2.Value;
                }
                officeHours.Note = reader["Note"].ToString();
                list.Add(officeHours);
            }
            return(NormalizeOfficeHours(list));
        }
コード例 #24
0
        public static List <OfficeHours> NormalizeOfficeHours(List <OfficeHours> officeHours)
        {
            bool flag;
            bool flag1;
            bool flag2;
            EuropeanDayOfWeek?nullable;

            if (!officeHours.Any <OfficeHours>())
            {
                return(officeHours);
            }
            List <OfficeHours> newList = new List <OfficeHours>();
            OfficeHours        newItem = officeHours.First <OfficeHours>();

            for (int i = 1; i < officeHours.Count; i++)
            {
                if (!string.IsNullOrWhiteSpace(newItem.Note) || !string.IsNullOrWhiteSpace(officeHours[i].Note))
                {
                    flag = (string.IsNullOrWhiteSpace(newItem.Note) || string.IsNullOrWhiteSpace(officeHours[i].Note) ? false : newItem.Note.Equals(officeHours[i].Note));
                }
                else
                {
                    flag = true;
                }
                bool     isEqualNotes = flag;
                DateTime?startTime    = newItem.StartTime;
                DateTime?endTime      = officeHours[i].StartTime;
                if (startTime.HasValue == endTime.HasValue)
                {
                    flag1 = (startTime.HasValue ? startTime.GetValueOrDefault() == endTime.GetValueOrDefault() : true);
                }
                else
                {
                    flag1 = false;
                }
                if (!flag1)
                {
                    flag2 = false;
                }
                else
                {
                    endTime   = newItem.EndTime;
                    startTime = officeHours[i].EndTime;
                    if (endTime.HasValue == startTime.HasValue)
                    {
                        flag2 = (endTime.HasValue ? endTime.GetValueOrDefault() == startTime.GetValueOrDefault() : true);
                    }
                    else
                    {
                        flag2 = false;
                    }
                }
                if (flag2 & isEqualNotes)
                {
                    EuropeanDayOfWeek?endDay = newItem.EndDay;
                    if (endDay.HasValue)
                    {
                        nullable = new EuropeanDayOfWeek?((int)endDay.GetValueOrDefault() + (int)EuropeanDayOfWeek.Monday);
                    }
                    else
                    {
                        nullable = null;
                    }
                    EuropeanDayOfWeek?nullable1 = nullable;
                    EuropeanDayOfWeek?endDay1   = officeHours[i].EndDay;
                    if (nullable1.GetValueOrDefault() != endDay1.GetValueOrDefault() | nullable1.HasValue != endDay1.HasValue)
                    {
                        goto Label1;
                    }
                    newItem.EndDay = officeHours[i].EndDay;
                    goto Label0;
                }
Label1:
                newList.Add(newItem);
                newItem = officeHours[i];
Label0:
            }
            newList.Add(newItem);
            return(newList);
        }
    }
コード例 #25
0
        public async Task <OperationResultWithData <List <SlotDto> > > RescheduleDate(int ohId, LmsUser lmsUser,
                                                                                      RescheduleDateDto dto)
        {
            List <SlotDto> result               = new List <SlotDto>();
            var            availabilities       = _availabilityModel.GetAvailabilities(ohId);
            var            availabilitiesToAdd  = new List <OfficeHoursTeacherAvailabilityDto>();
            var            slotsToAdd           = new List <SlotDto>();
            var            overlappingFreeSlots = new List <SlotDto>();
            OfficeHours    oh = null;

            foreach (var availability in availabilities)
            {
                var availabilityDto = ConvertToDto(availability);
                var slots           = GetSlotsForAvailability(availabilityDto, dto.Start, dto.End, lmsUser.Id, availability);
                if (slots.Any())
                {
                    var newAvailabilityDto =
                        BuildAvailabilityBySlots(slots, dto.FirstSlotTimeshift, availability.Duration);
                    oh = oh ?? availability.Meeting;
                    var overlappingSlots = await ValidateSlotsRange(oh, lmsUser.Id, newAvailabilityDto);

                    if (overlappingSlots.Any(x => x.Status != (int)OfficeHoursSlotStatus.Free))
                    {
                        return(OperationResultWithData <List <SlotDto> > .Error(
                                   "The range of dates overlaps another date range. Please choose another date range."));
                    }
                    if (overlappingSlots.Any(x => (x.End - x.Start).Minutes != availability.Duration))
                    {
                        return(OperationResultWithData <List <SlotDto> > .Error(
                                   "The duration of new slots doesn't match duration of overalpped free slots."));
                    }
                    if (overlappingSlots.Any())
                    {
                        var slotsForAvailability = slots.Where(x =>
                                                               overlappingSlots.All(os => os.Start != x.Start.AddMilliseconds(dto.FirstSlotTimeshift)));
                        if (slotsForAvailability.Any())
                        {
                            newAvailabilityDto = BuildAvailabilityBySlots(slotsForAvailability, dto.FirstSlotTimeshift,
                                                                          availability.Duration);
                        }
                        else
                        {
                            slotsToAdd.AddRange(slots);
                            continue;
                        }
                    }
                    availabilitiesToAdd.Add(newAvailabilityDto);
                    slotsToAdd.AddRange(slots);
                }
            }

            foreach (var availabilityDto in availabilitiesToAdd)
            {
                var a = await AddAvailability(oh, lmsUser, availabilityDto);

                if (!a.IsSuccess)
                {
                    //todo: delete already added availabilities
                    return(OperationResultWithData <List <SlotDto> > .Error(a.Message));
                }
            }
            var notAddedSlots = new List <string>();
            var deniedSlots   = new List <SlotDto>();
            //var details = await _meetingService.GetMeetingApiDetails(meeting);
            //if (dto.KeepRegistration)
            //{
            var dbSlots = _slotModel.GetSlotsForDate(dto.Start, dto.End, ohId);

            foreach (var slotDto in slotsToAdd) //todo: add many slots at once
            {
                if (slotDto.Status == (int)OfficeHoursSlotStatus.Booked)
                {
                    slotDto.Start = slotDto.Start.AddMilliseconds(dto.FirstSlotTimeshift);
                    slotDto.End   = slotDto.End.AddMilliseconds(dto.FirstSlotTimeshift);
                    if (dto.KeepRegistration)
                    {
                        var s = await AddSlots(oh.Id, dbSlots.First(x => x.Id == slotDto.Id).User, new[] { slotDto });

                        if (!s.IsSuccess)
                        {
                            notAddedSlots.Add(slotDto.UserName);
                            slotDto.Id        = 0;
                            slotDto.Status    = (int)OfficeHoursSlotStatus.Free;
                            slotDto.Subject   = null;
                            slotDto.Questions = null;
                            slotDto.UserName  = null;
                            slotDto.CanEdit   = false;
                        }
                        if (s.IsSuccess && !string.IsNullOrEmpty(dto.Message))
                        {
                            //await _notificationService.SendOHRescheduleEmail(slotDto.Start, s.Data.First(),
                            //    details.Topic, dto.Message);
                        }
                    }
                    else
                    {
                        //await _notificationService.SendOHCancellationEmail(slotDto.Start, details.Topic, dto.Message, slotDto.UserName);
                    }
                    var updateResult = await UpdateSlotStatusInternal(slotDto.Id, OfficeHoursSlotStatus.Cancelled, lmsUser);

                    result.Add(slotDto);
                }

                //
                else
                {
                    deniedSlots.Add(slotDto);
                }
            }
            //}
            var denyFreeSlotsResult = await AddSlots(oh.Id, lmsUser, deniedSlots, OfficeHoursSlotStatus.Cancelled);

            deniedSlots.ForEach(x =>
            {
                x.Start = x.Start.AddMilliseconds(dto.FirstSlotTimeshift);
                x.End   = x.End.AddMilliseconds(dto.FirstSlotTimeshift);
            });

            result.AddRange(deniedSlots);
            var opResult = result.ToSuccessResult();

            if (notAddedSlots.Any())
            {
                opResult.Message = $"Slots for the following users were not moved: {String.Join(", ", notAddedSlots)}";
            }

            return(opResult);
        }
コード例 #26
0
        public async Task <Course[]> GetAll()
        {
            dynamic obj = await Request.Content.ReadAsAsync <JObject>();

            int id;

            try {
                id = obj.userId;
            } catch (Exception ex) {
                Debug.WriteLine("[ScheduleController::GetAll] invalid request payload");
                throw ex;
            }

            var connString = ConfigurationManager.ConnectionStrings[profile].ConnectionString;

            try {
                using (var conn = new SqlConnection(connString)) {
                    conn.Open();
                    var query = "select course.id, course.name, course.department, "
                                + "course.courseNumber, course.courseSection, courseTimes.weekday, "
                                + "courseTimes.startTime, courseTimes.endTime, professor.name, "
                                + "professor.phone, professor.email, officeHours.startTime, "
                                + "officeHours.endTime, officeHours.weekday, location.buildingName, "
                                + "location.roomNumber "
                                + "from student, enroll, course, courseTimes, professor, officeHours, "
                                + "location "
                                + "where student.id = enroll.studentId and "
                                + "course.id = enroll.courseId and "
                                + "course.locationId = location.id and "
                                + "course.professorId = professor.id and "
                                + "courseTimes.courseId = course.id and "
                                + "officeHours.professorId = professor.id and "
                                + "student.id = @id";

                    using (var cmd = new SqlCommand(query, conn)) {
                        cmd.Parameters.Add("@id", SqlDbType.Int).Value = id;
                        using (var reader = cmd.ExecuteReader()) {
                            var courses = new List <Course>();

                            getCourse :  while (reader.Read())
                            {
                                var id_      = reader.GetInt32(0);
                                var existing = courses.Find((c) => c.Id == id_);

                                if (existing != null)
                                {
                                    var weekday      = reader.GetString(5);
                                    var officeHours_ = new OfficeHours(
                                        reader.GetTimeSpan(11),
                                        reader.GetTimeSpan(12),
                                        reader.GetString(13)
                                        );

                                    if (!Array.Exists(existing.Days, e => e == weekday))
                                    {
                                        var newDays = new string[1 + existing.Days.Length];
                                        for (int i = 0; i < existing.Days.Length; i++)
                                        {
                                            newDays[i] = existing.Days[i];
                                        }
                                        newDays[newDays.Length - 1] = weekday;
                                        existing.Days = newDays;
                                    }
                                    if (!Array.Exists(
                                            existing.OfficeHours,
                                            e => e == officeHours_)
                                        )
                                    {
                                        var newHours =
                                            new OfficeHours[1 + existing.OfficeHours.Length];
                                        for (int i = 0; i < existing.OfficeHours.Length; i++)
                                        {
                                            newHours[i] = existing.OfficeHours[i];
                                        }
                                        newHours[newHours.Length - 1] = officeHours_;
                                        existing.OfficeHours          = newHours;
                                    }

                                    goto getCourse;
                                }

                                var courseName       = reader.GetString(1);
                                var courseDepartment = reader.GetString(2);
                                var courseNumber     = reader.GetInt32(3);
                                var courseSection    = reader.GetInt32(4);
                                var days             = new string[] {
                                    reader.GetString(5),
                                };
                                var startTime      = reader.GetTimeSpan(6);
                                var endTime        = reader.GetTimeSpan(7);
                                var professor      = reader.GetString(8);
                                var professorPhone = reader.GetString(9);
                                var professorEmail = reader.GetString(10);
                                var officeHours    = new OfficeHours[] {
                                    new OfficeHours(
                                        reader.GetTimeSpan(11),
                                        reader.GetTimeSpan(12),
                                        reader.GetString(13)
                                        ),
                                };
                                var buildingName = reader.GetString(14);
                                var roomNumber   = reader.GetString(15);
                                courses.Add(new Course {
                                    Id            = id_,
                                    CourseName    = courseName,
                                    Department    = courseDepartment,
                                    CourseNumber  = courseNumber,
                                    SectionNumber = courseSection,
                                    StartTime     = startTime,
                                    EndTime       = endTime,
                                    Days          = days,
                                    Professor     = professor,
                                    Phone         = professorPhone,
                                    Email         = professorEmail,
                                    OfficeHours   = officeHours,
                                    Building      = buildingName,
                                    RoomNumber    = roomNumber,
                                });
                            }
                            Debug.WriteLine("[ScheduleController::GetAll] "
                                            + "returning info for student "
                                            + id.ToString() + ": " + courses.ToString());
                            return(courses.ToArray());
                        }
                    }
                }
            } catch (Exception ex) {
                Debug.WriteLine("[ScheduleController::GetAll] failed to access database: "
                                + ex.Message);
                Debug.WriteLine(ex.StackTrace);
                throw ex;
            }
        }
コード例 #27
0
        public async Task <OperationResultWithData <OfficeHoursTeacherAvailabilityDto> > AddAvailability(OfficeHours oh, LmsUser lmsUser, OfficeHoursTeacherAvailabilityDto availabilityDto)
        {
            var overlappingSlots = await ValidateSlotsRange(oh, lmsUser.Id, availabilityDto);

            if (overlappingSlots.Any())
            {
                return(OperationResultWithData <OfficeHoursTeacherAvailabilityDto> .Error(
                           "The range of dates overlaps another date range. Please choose another date range."));
            }
            var entity = ConvertFromDto(oh, lmsUser, availabilityDto);

            _availabilityModel.RegisterSave(entity, true);
            return(ConvertToDto(entity).ToSuccessResult());
        }