Пример #1
0
        public HttpResponseMessage GetTimeSlots(int codeCampId)
        {
            try
            {
                var slotsToOrder = TimeSlotDataAccess.GetItems(codeCampId);
                var timeSlots    = TimeSlotInfoController.SortTimeSlots(slotsToOrder);

                var response = new ServiceResponse <List <TimeSlotInfo> > {
                    Content = timeSlots.ToList()
                };

                if (timeSlots == null)
                {
                    ServiceResponseHelper <List <TimeSlotInfo> > .AddNoneFoundError("timeSlots", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
Пример #2
0
        public HttpResponseMessage CreateTimeSlot(TimeSlotInfo timeSlot)
        {
            try
            {
                var timeStamp = DateTime.Now;

                timeSlot.CreatedByDate       = timeStamp;
                timeSlot.CreatedByUserId     = UserInfo.UserID;
                timeSlot.LastUpdatedByDate   = timeStamp;
                timeSlot.LastUpdatedByUserId = UserInfo.UserID;

                TimeSlotDataAccess.CreateItem(timeSlot);

                var timeSlots = TimeSlotDataAccess.GetItems(timeSlot.CodeCampId);

                var savedTimeSlot = timeSlots.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.BeginTime == timeSlot.BeginTime);

                // removing this prevented the saved/retrieved time from being offset to being about 4 hours off
                //if (savedTimeSlot != null)
                //{
                //    savedTimeSlot.BeginTime = savedTimeSlot.BeginTime.ToLocalTime();
                //    savedTimeSlot.EndTime = savedTimeSlot.EndTime.ToLocalTime();
                //}

                var response = new ServiceResponse <TimeSlotInfo> {
                    Content = savedTimeSlot
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage GetAgenda(int codeCampId)
        {
            try
            {
                var agenda = new AgendaInfo();
                agenda.CodeCamp = CodeCampDataAccess.GetItem(codeCampId, ActiveModule.ModuleID);

                if (agenda.CodeCamp != null)
                {
                    var slotsToOrder  = TimeSlotDataAccess.GetItems(codeCampId);
                    var timeSlots     = TimeSlotInfoController.SortTimeSlots(slotsToOrder);
                    var timeSlotCount = timeSlots.Count();

                    // determine how many days the event lasts for
                    agenda.NumberOfDays = (int)(agenda.CodeCamp.EndDate - agenda.CodeCamp.BeginDate).TotalDays + 1;

                    // iterate through each day
                    agenda.EventDays = new List <EventDayInfo>();

                    var dayCount = 0;
                    while (dayCount <= agenda.NumberOfDays - 1)
                    {
                        var eventDate = agenda.CodeCamp.BeginDate.AddDays(dayCount);

                        var eventDay = new EventDayInfo()
                        {
                            Index     = dayCount,
                            Day       = eventDate.Day,
                            Month     = eventDate.Month,
                            Year      = eventDate.Year,
                            TimeStamp = eventDate
                        };

                        eventDay.TimeSlots = new List <AgendaTimeSlotInfo>();

                        // iterate through each timeslot
                        foreach (var timeSlot in timeSlots)
                        {
                            var slot = new AgendaTimeSlotInfo(timeSlot);

                            if (!timeSlot.SpanAllTracks)
                            {
                                // iterate through each session
                                slot.Sessions = SessionDataAccess.GetItemsByTimeSlotIdByPage(slot.TimeSlotId, codeCampId, dayCount + 1, timeSlotCount).ToList();

                                // iterate through each speaker
                                foreach (var session in slot.Sessions)
                                {
                                    session.Speakers = SpeakerDataAccess.GetSpeakersForCollection(session.SessionId, codeCampId);
                                }
                            }
                            else
                            {
                                // add the full span session item
                                // TODO: allow for items to be added to full span timeslots
                            }

                            eventDay.TimeSlots.Add(slot);
                        }

                        agenda.EventDays.Add(eventDay);

                        dayCount++;
                    }
                }

                var response = new ServiceResponse <AgendaInfo> {
                    Content = agenda
                };

                if (agenda.CodeCamp == null)
                {
                    ServiceResponseHelper <AgendaInfo> .AddNoneFoundError("AgendaInfo", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }