public HttpResponseMessage UserCanEditEvent(int itemId)
        {
            ServiceResponse <string> response = null;

            if (UserInfo.IsSuperUser || UserInfo.IsInRole(PortalSettings.AdministratorRoleName) || ModulePermissionController.HasModulePermission(ActiveModule.ModulePermissions, "Edit"))
            {
                response = new ServiceResponse <string>()
                {
                    Content = Globals.RESPONSE_SUCCESS
                };
            }
            else
            {
                var codeCamp = CodeCampDataAccess.GetItem(itemId, ActiveModule.ModuleID);

                if (codeCamp != null && codeCamp.CreatedByUserId == UserInfo.UserID || codeCamp.LastUpdatedByUserId == UserInfo.UserID)
                {
                    response = new ServiceResponse <string>()
                    {
                        Content = Globals.RESPONSE_SUCCESS
                    };
                }
                else
                {
                    response = new ServiceResponse <string>()
                    {
                        Content = Globals.RESPONSE_FAILURE
                    };
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
        }
        public HttpResponseMessage UpdateEvent(CodeCampInfo codeCamp)
        {
            try
            {
                var originalEvent    = CodeCampDataAccess.GetItem(codeCamp.CodeCampId, codeCamp.ModuleId);
                var updatesToProcess = EventHasUpdates(ref originalEvent, ref codeCamp);

                if (updatesToProcess)
                {
                    originalEvent.LastUpdatedByDate   = DateTime.Now;
                    originalEvent.LastUpdatedByUserId = UserInfo.UserID;

                    CodeCampDataAccess.UpdateItem(originalEvent);
                }

                var savedEvent = CodeCampDataAccess.GetItem(originalEvent.CodeCampId, originalEvent.ModuleId);

                var response = new ServiceResponse <CodeCampInfo> {
                    Content = savedEvent
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage DeleteEvent(int itemId)
        {
            try
            {
                CodeCampDataAccess.DeleteItem(itemId, ActiveModule.ModuleID);
                var response = new ServiceResponse <string> {
                    Content = SUCCESS_MESSAGE
                };

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage GetEvents()
        {
            try
            {
                var codeCamps = CodeCampDataAccess.GetItems(ActiveModule.ModuleID);
                var response  = new ServiceResponse <List <CodeCampInfo> > {
                    Content = codeCamps.ToList()
                };

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

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage CreateEvent(CodeCampInfo newEvent)
        {
            try
            {
                newEvent.CreatedByDate       = DateTime.Now;
                newEvent.CreatedByUserId     = UserInfo.UserID;
                newEvent.LastUpdatedByDate   = DateTime.Now;
                newEvent.LastUpdatedByUserId = UserInfo.UserID;
                newEvent.ModuleId            = ActiveModule.ModuleID;

                CodeCampDataAccess.CreateItem(newEvent);

                var response = new ServiceResponse <string> {
                    Content = Globals.RESPONSE_SUCCESS
                };

                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));
            }
        }