Beispiel #1
0
        public IEnumerable <IEvent> GetByClassRoom(int id, DateTime dateEventsFrom, DateTime dateEventsTo)
        {
            var eventsInClassroom = new List <IEvent>();

            using (var context = new ClassBookingContext())
            {
                var events = context.Events
                             .Where(e => e.BeginingDate >= dateEventsFrom && e.EndingDate <= dateEventsTo &&
                                    e.ClassRoomId == id)
                             .OrderBy(e => e.BeginingDate)
                             .Select(e => new EventModel()
                {
                    Id           = e.Id,
                    Title        = e.Title,
                    ClassRoomId  = e.ClassRoomId,
                    BeginingDate = e.BeginingDate,
                    EndingDate   = e.EndingDate,
                    IsPrivate    = e.IsPrivate,
                    Description  = e.Description.Substring(0, EventSettings.MaxCharactersInBriefDescription)
                })
                             .ToList();

                foreach (var eventBrief in events)
                {
                    eventsInClassroom.Add(eventBrief);
                }
            }

            return(eventsInClassroom);
        }
Beispiel #2
0
        public void ChangeRoomStatus(int id, ClassRoomStatus classRoomStatus)
        {
            using (var context = new ClassBookingContext())
            {
                var classRoom = context.ClassRooms.Find(id);
                context.ClassRooms.Attach(classRoom);
                var entry = context.Entry(classRoom);
                switch (classRoomStatus)
                {
                case ClassRoomStatus.Opened:
                    classRoom.IsLocked = false;
                    break;

                case ClassRoomStatus.Closed:
                    classRoom.IsLocked = true;

                    var eventsToDelete = context.Events.Where(e => e.ClassRoomId == id).ToList();
                    foreach (var eventToDelete in eventsToDelete)
                    {
                        context.Participants.RemoveRange(
                            context.Participants.Where(p => p.EventId == eventToDelete.Id));
                    }

                    context.Events.RemoveRange(context.Events.Where(e => e.ClassRoomId == id));

                    break;
                }
                entry.Property(e => e.IsLocked).IsModified = true;
                context.SaveChanges();
            }
        }
Beispiel #3
0
        public void Add(IParticipant participaModel)
        {
            using (var context = new ClassBookingContext())
            {
                var duplicatedEmails = context.Participants
                                       .Count(p => p.EventId == participaModel.EventId &&
                                              p.Email == participaModel.Email);

                if (duplicatedEmails > 0)
                {
                    throw new ParticipantAlreadyRegisteredException();
                }

                var alreadyRegisteredCount = context.Participants.Count(p => p.EventId == participaModel.EventId);
                var roomId =
                    context.Events.Where(e => e.Id == participaModel.EventId).Select(e => e.ClassRoomId).FirstOrDefault();
                var roomCapacity =
                    context.ClassRooms.Where(c => c.Id == roomId).Select(c => c.Capacity).FirstOrDefault();

                if (alreadyRegisteredCount >= roomCapacity)
                {
                    throw new ParticipantCountReachedMaximumRoomCapacityException();
                }

                context.Participants.Add(new Participants
                {
                    Email   = participaModel.Email,
                    EventId = participaModel.EventId
                });
                context.SaveChanges();
            }
        }
Beispiel #4
0
        public IEnumerable <IEvent> GetByUser(string id)
        {
            var eventsList = new List <IEvent>();
            var dateNow    = DateTime.UtcNow.AddHours(EventSettings.DateTimeUtcOffset);

            using (var context = new ClassBookingContext())
            {
                var userEmail = ServiceHelper.GetUserEmail(id);

                var events = (from e in context.Events
                              join p in context.Participants on e.Id equals p.EventId
                              where e.EndingDate > dateNow && p.Email == userEmail
                              select new EventModel
                {
                    Id = e.Id,
                    ClassRoomId = e.ClassRoomId,
                    BeginingDate = e.BeginingDate,
                    EndingDate = e.EndingDate,
                    Title = e.Title,
                    Description = e.Description,
                    IsPrivate = e.IsPrivate
                }).ToList();


                foreach (var _event in events)
                {
                    eventsList.Add(_event);
                }
            }
            return(eventsList);
        }
Beispiel #5
0
 public IEvent Get(int id)
 {
     using (var context = new ClassBookingContext())
     {
         return(MapService.Map(context.Events.Find(id)));
     }
 }
Beispiel #6
0
        List<BookingStatus> IBookingRule.RemoveInvalidBookingStatus(StudentBookingContext studentBookingContext, ClassBookingContext classBookingContext)
        {
            List<BookingStatus> result = null;

            switch ((ClassCategory)classBookingContext.ScheduledClassInfo.ClassCategory_id)
            {
                case ClassCategory.F2F:
                    break;
                case ClassCategory.WS:
                    break;
                case ClassCategory.LC:
                case ClassCategory.CW:
                    //if (studentBookingContext.StuentProductInfo.ProductID == ProductPackage_Ids.AlumniClub)
                    //{
                    //    if (studentBookingContext.BookingSummary.LCCWQtyPerMonth >= studentBookingContext.StuentProductInfo.LCCW_PerMonth
                    //    || studentBookingContext.BookingSummary.LCCWQtyPerWeek >= studentBookingContext.StuentProductInfo.LCCW_PerWeek)
                    //    {
                    //        result = new List<BookingStatus>() { BookingStatus.All };
                    //    }
                    //    else if (studentBookingContext.BookingSummary.LGQtyPerOpen >= studentBookingContext.StuentProductInfo.LG_PerTime)
                    //    {
                    //        result = new List<BookingStatus>() { BookingStatus.Booked, BookingStatus.Waiting };
                    //    }
                    //}

                    break;
                default:
                    break;
            }

            return result;
        }
Beispiel #7
0
 public IClassRoom Get(int id)
 {
     using (var context = new ClassBookingContext())
     {
         return(MapService.Map(context.ClassRooms.Find(id)));
     }
 }
Beispiel #8
0
        public void Add(IEvent eventModel)
        {
            using (var context = new ClassBookingContext())
            {
                if (ServiceHelper.IsRoomBusy(eventModel))
                {
                    throw new RoomIsBusyException();
                }

                var roomCapacity = context.ClassRooms
                                   .Where(c => c.Id == eventModel.ClassRoomId)
                                   .Select(c => c.Capacity).FirstOrDefault();

                if (roomCapacity < 1)
                {
                    throw new RoomCapacityException();
                }

                var events    = MapService.Map(eventModel);
                var userEmail = ServiceHelper.GetUserEmail(eventModel.UserId);

                context.Events.Add(events);
                context.Participants.Add(new Participants
                {
                    EventId = events.Id,
                    Email   = userEmail
                });

                context.SaveChanges();
            }
        }
Beispiel #9
0
 public int GetCount(int eventId)
 {
     using (var context = new ClassBookingContext())
     {
         return(context.Participants.Count(p => p.EventId == eventId));
     }
 }
Beispiel #10
0
 public void Add(IClassRoom classRoom)
 {
     using (var context = new ClassBookingContext())
     {
         context.ClassRooms.Add(MapService.Map(classRoom));
         context.SaveChanges();
     }
 }
 public void Add(IFeedback feedbackModel)
 {
     using (var context = new ClassBookingContext())
     {
         context.Feedbacks.Add(MapService.Map(feedbackModel));
         context.SaveChanges();
     }
 }
 public static string GetUserEmail(string id)
 {
     using (var context = new ClassBookingContext())
     {
         return(context.AspNetUsers.Where(u => u.Id == id)
                .Select(u => u.Email)
                .FirstOrDefault());
     }
 }
Beispiel #13
0
        public int GetNumberOfEventsByUser(string id)
        {
            var eventsList = new List <IEvent>();

            int count = 0;

            using (var context = new ClassBookingContext())
            {
                count = context.Events.Where(e => e.UserId == id).ToList().Count;
            }
            return(count);
        }
Beispiel #14
0
        public bool IsTakePart(int eventId, string userId)
        {
            using (var context = new ClassBookingContext())
            {
                var userEmail = ServiceHelper.GetUserEmail(userId);

                var userCount = context.Participants.Count(
                    p => p.EventId == eventId &&
                    p.Email == userEmail);

                return(userCount > 0);
            }
        }
Beispiel #15
0
        public void Remove(IClassRoom classRoom)
        {
            var classRooms = new ClassRooms
            {
                Id = classRoom.Id
            };

            using (var context = new ClassBookingContext())
            {
                context.ClassRooms.Attach(classRooms);
                context.ClassRooms.Remove(classRooms);
                context.SaveChanges();
            }
        }
Beispiel #16
0
        public IEnumerable <IClassRoom> Get()
        {
            var classRoomModel = new List <IClassRoom>();

            using (var context = new ClassBookingContext())
            {
                var classRooms = context.ClassRooms.ToList();
                foreach (var classRoom in classRooms)
                {
                    classRoomModel.Add(MapService.Map(classRoom));
                }
            }
            return(classRoomModel);
        }
Beispiel #17
0
        public IEnumerable <IEvent> Get()
        {
            var eventsList = new List <IEvent>();

            using (var context = new ClassBookingContext())
            {
                var events = context.Events.ToList();
                foreach (var _event in events)
                {
                    eventsList.Add(MapService.Map(_event));
                }
            }
            return(eventsList);
        }
Beispiel #18
0
        public IEnumerable <IParticipant> Get(int eventId)
        {
            var participantModelList = new List <IParticipant>();

            using (var context = new ClassBookingContext())
            {
                var participants = context.Participants
                                   .Where(p => p.EventId == eventId)
                                   .ToList();
                foreach (var participant in participants)
                {
                    participantModelList.Add(MapService.Map(participant));
                }
            }

            return(participantModelList);
        }
Beispiel #19
0
        public void Update(IEvent eventModel, IEvent pivotModel)
        {
            if (eventModel.ClassRoomId != pivotModel.ClassRoomId)
            {
                if (ServiceHelper.IsRoomBusy(eventModel))
                {
                    throw new RoomIsBusyException();
                }
            }

            if (DateTime.Compare(eventModel.BeginingDate, pivotModel.BeginingDate) < 0)
            {
                if (ServiceHelper.IsRoomBusy(new EventModel
                {
                    BeginingDate = eventModel.BeginingDate,
                    EndingDate = pivotModel.BeginingDate,
                    ClassRoomId = eventModel.ClassRoomId
                }))
                {
                    throw new RoomIsBusyException();
                }
            }

            if (DateTime.Compare(eventModel.EndingDate, pivotModel.EndingDate) > 0)
            {
                if (ServiceHelper.IsRoomBusy(new EventModel
                {
                    BeginingDate = pivotModel.EndingDate,
                    EndingDate = eventModel.EndingDate,
                    ClassRoomId = eventModel.ClassRoomId
                }))
                {
                    throw new RoomIsBusyException();
                }
            }

            var events = MapService.Map(eventModel);

            using (var context = new ClassBookingContext())
            {
                context.Events.Attach(events);
                context.Entry(events).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
Beispiel #20
0
        public void Update(IClassRoom classRoom)
        {
            var updatedClassRoom = MapService.Map(classRoom);

            using (var context = new ClassBookingContext())
            {
                var old = context.ClassRooms.FirstOrDefault(c => c.Id == updatedClassRoom.Id);
                if (old != null)
                {
                    context.Entry(old).CurrentValues.SetValues(updatedClassRoom);
                    context.SaveChanges();
                }
                else
                {
                    throw new ObjectNotFoundException();
                }
            }
        }
Beispiel #21
0
        public void Remove(IEvent eventModel)
        {
            var events = new Events
            {
                Id = eventModel.Id
            };

            using (var context = new ClassBookingContext())
            {
                context.Participants.RemoveRange(context.Participants
                                                 .Where(p => p.EventId == events.Id));

                context.Events.Attach(events);
                context.Events.Remove(events);

                context.SaveChanges();
            }
        }
Beispiel #22
0
        public void RemoveAllEventsFromUser(string id)
        {
            var eventsList = new List <IEvent>();
            var dateNow    = DateTime.Now;

            using (var context = new ClassBookingContext())
            {
                var events = context.Events.Where(e => e.UserId == id).ToList();
                foreach (var _event in events)
                {
                    context.Participants.RemoveRange(context.Participants
                                                     .Where(p => p.EventId == _event.Id));

                    context.Events.Attach(_event);
                    context.Events.Remove(_event);
                }
                context.SaveChanges();
            }
        }
        public static bool IsRoomBusy(IEvent eventModel)
        {
            using (var context = new ClassBookingContext())
            {
                var eventsInSameRange = context.Events
                                        .Count(
                    e => ((e.BeginingDate > eventModel.BeginingDate && e.BeginingDate < eventModel.EndingDate) ||
                          (e.EndingDate > eventModel.BeginingDate && e.EndingDate < eventModel.EndingDate) ||
                          (e.BeginingDate > eventModel.BeginingDate && e.BeginingDate < eventModel.EndingDate) ||
                          (e.BeginingDate <eventModel.BeginingDate && e.EndingDate> eventModel.EndingDate)) &&
                    (e.ClassRoomId == eventModel.ClassRoomId));

                if (eventsInSameRange > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #24
0
        public void Remove(IParticipant paricipantModel)
        {
            var participants = new Participants();

            using (var context = new ClassBookingContext())
            {
                if (paricipantModel.Id > 0)
                {
                    participants.Id = paricipantModel.Id;
                }
                else
                {
                    participants = context.Participants.FirstOrDefault(p => p.Email == paricipantModel.Email);
                }

                context.Participants.Attach(participants);
                context.Participants.Remove(participants);

                context.SaveChanges();
            }
        }
Beispiel #25
0
        public IEnumerable <object> GetNameId()
        {
            var listOfAttributes = new List <object>();

            using (var context = new ClassBookingContext())
            {
                var attributes = context.ClassRooms.Where(field => field.IsLocked == false)
                                 .Select(field => new
                {
                    field.Id,
                    field.Name
                })
                                 .ToList();

                foreach (var attribute in attributes)
                {
                    listOfAttributes.Add(attribute);
                }
            }

            return(listOfAttributes);
        }
Beispiel #26
0
        public List<BookingStatus> RemoveInvalidBookingStatus(StudentBookingContext studentBookingContext, ClassBookingContext classBookingContext)
        {
            List<BookingStatus> result = null;

            ClassCategory classCategory = (ClassCategory)classBookingContext.ScheduledClassInfo.ClassCategory_id;

            //predefined class category group info list
            var groupInfoList = ClassCategoryGroupCacheSvc.Instance.GetClassCategoryGroupInfoByClassCategory(classCategory);

            foreach (var groupInfo in groupInfoList)
            {
                var bookingLimitLkpList = BookingLimitLkpList.LoadBookingLimitLkp(groupInfo.ClassCategoryGroup_id, studentBookingContext.Student.Product_id.GetValueOrDefault());

                if (bookingLimitLkpList != null && bookingLimitLkpList.Count > 0)
                {
                    //check booking limit

                    var bookingLimitLkp = bookingLimitLkpList.First();

                    // PremiumV1's weekcount doesn't include no F2F standby classes
                    int weekCount = studentBookingContext.StudentSelectedWeekBooking.BookingInfoList.Count(
                        info => groupInfo.ClassCategory_ids.Any(id => id == ScheduledClassCacheSvc.Instance.LoadByScheduledClass_id(info.ScheduledClass_id).ClassCategory_id)
                        && (info.BookingStatus_id == (short)BookingStatus.Booked
                            || (info.BookingStatus_id == (short)BookingStatus.Standby
                                && (classCategory == ClassCategory.F2F
                                    || studentBookingContext.Student.Product_id.Value != (short)ProductPackage_Ids.PremiumV1
                                    )
                                )
                            || info.BookingStatus_id == (short)BookingStatus.Checkin
                            || info.BookingStatus_id == (short)BookingStatus.NoShow
                            || info.BookingStatus_id == (short)BookingStatus.Waiting
                            || info.BookingStatus_id == (short)BookingStatus.TentativelyBooked
                        )
                        );

                    int monthCount = studentBookingContext.StudentSelectedMonthBooking.BookingInfoList.Count(
                        info => groupInfo.ClassCategory_ids.Any(id => id == ScheduledClassCacheSvc.Instance.LoadByScheduledClass_id(info.ScheduledClass_id).ClassCategory_id)
                        && (info.BookingStatus_id == (short)BookingStatus.Booked
                            || info.BookingStatus_id == (short)BookingStatus.Standby
                            || info.BookingStatus_id == (short)BookingStatus.Checkin
                            || info.BookingStatus_id == (short)BookingStatus.NoShow
                            || info.BookingStatus_id == (short)BookingStatus.Waiting
                            || info.BookingStatus_id == (short)BookingStatus.TentativelyBooked
                        )
                        );

                    int openCount = studentBookingContext.StudentBookingInfo.BookingInfoList.Count(
                        info => groupInfo.ClassCategory_ids.Any(id => id == ScheduledClassCacheSvc.Instance.LoadByScheduledClass_id(info.ScheduledClass_id).ClassCategory_id)
                        && (info.BookingStatus_id == (short)BookingStatus.Booked
                            || info.BookingStatus_id == (short)BookingStatus.Waiting
                            || info.BookingStatus_id == (short)BookingStatus.TentativelyBooked
                            || info.BookingStatus_id == (short)BookingStatus.Standby
                        )
                        );

                    if (bookingLimitLkp.WeekLimit.HasValue && 0 <= bookingLimitLkp.WeekLimit.Value && bookingLimitLkp.WeekLimit.Value <= weekCount)
                    {
                        // PremiumV1 can standy WS,LC,CW class when reach weeklimit.
                        if (studentBookingContext.Student.Product_id.Value == (short)ProductPackage_Ids.PremiumV1
                            && classCategory != ClassCategory.F2F)
                        {
                            return new List<BookingStatus>() { BookingStatus.Booked, BookingStatus.Waiting, BookingStatus.TentativelyBooked };
                        }
                        else
                        {
                            return new List<BookingStatus>() { BookingStatus.All };
                        }
                    }

                    if (bookingLimitLkp.MonthLimit.HasValue && 0 <= bookingLimitLkp.MonthLimit.Value && bookingLimitLkp.MonthLimit.Value <= monthCount)
                    {
                        return new List<BookingStatus>() { BookingStatus.All };
                    }

                    if (bookingLimitLkp.OpenLimit.HasValue && 0 <= bookingLimitLkp.OpenLimit.Value && bookingLimitLkp.OpenLimit.Value <= openCount)
                    {
                        return new List<BookingStatus>() { BookingStatus.All };
                    }
                }
            }

            return result;
        }