public HttpResponseMessage UnassignSessionFromTrack(int sessionId, int codeCampId)
        {
            try
            {
                var session = SessionDataAccess.GetItem(sessionId, codeCampId);

                session.TrackId = null;

                session.LastUpdatedByDate   = DateTime.Now;
                session.LastUpdatedByUserId = UserInfo.UserID;

                SessionDataAccess.UpdateItem(session);

                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));
            }
        }
Exemple #2
0
        public HttpResponseMessage UnassignTimeSlotFromSession(int sessionId, int timeSlotId, int codeCampId)
        {
            try
            {
                var session = SessionDataAccess.GetItem(sessionId, codeCampId);

                if (session != null)
                {
                    session.TimeSlotId          = null;
                    session.LastUpdatedByDate   = DateTime.Now;
                    session.LastUpdatedByUserId = UserInfo.UserID;

                    SessionDataAccess.UpdateItem(session);
                }

                var response = new ServiceResponse <string> {
                    Content = SUCCESS_MESSAGE
                };

                if (session == null)
                {
                    ServiceResponseHelper <string> .AddNoneFoundError("session", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage GetSession(int itemId)
        {
            try
            {
                var session  = SessionDataAccess.GetItem(itemId, ActiveModule.ModuleID);
                var response = new ServiceResponse <SessionInfo> {
                    Content = session
                };

                if (session == null)
                {
                    ServiceResponseHelper <SessionInfo> .AddNoneFoundError("session", ref response);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson()));
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE));
            }
        }
        public HttpResponseMessage UpdateSession(SessionInfo session)
        {
            try
            {
                var updatesToProcess = false;
                var originalSession  = SessionDataAccess.GetItem(session.SessionId, session.CodeCampId);

                if (!string.Equals(session.Title, originalSession.Title))
                {
                    originalSession.Title = session.Title;
                    updatesToProcess      = true;
                }

                if (!string.Equals(session.Description, originalSession.Description))
                {
                    originalSession.Description = session.Description;
                    updatesToProcess            = true;
                }

                if (session.AudienceLevel != originalSession.AudienceLevel)
                {
                    originalSession.AudienceLevel = session.AudienceLevel;
                    updatesToProcess = true;
                }

                if (session.TrackId != originalSession.TrackId)
                {
                    originalSession.TrackId = session.TrackId;
                    updatesToProcess        = true;
                }

                if (originalSession.CustomProperties != null)
                {
                    // parse custom properties for updates
                    foreach (var property in originalSession.CustomPropertiesObj)
                    {
                        if (session.CustomPropertiesObj.Any(p => p.Name == property.Name))
                        {
                            // see if the existing property needs to be updated
                            var prop = session.CustomPropertiesObj.FirstOrDefault(p => p.Name == property.Name);
                            if (!string.Equals(prop.Value, property.Value))
                            {
                                property.Value   = prop.Value;
                                updatesToProcess = true;
                            }
                        }
                        else
                        {
                            // delete the property
                            originalSession.CustomPropertiesObj.Remove(property);
                            updatesToProcess = true;
                        }
                    }
                }

                if (session.CustomPropertiesObj != null)
                {
                    // add any new properties
                    if (originalSession.CustomProperties == null)
                    {
                        foreach (var property in session.CustomPropertiesObj)
                        {
                            originalSession.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                    else
                    {
                        foreach (var property in session.CustomPropertiesObj.Where(property => !originalSession.CustomPropertiesObj.Contains(property)))
                        {
                            originalSession.CustomPropertiesObj.Add(property);
                            updatesToProcess = true;
                        }
                    }
                }

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

                    SessionDataAccess.UpdateItem(session);
                }

                var savedSession = SessionDataAccess.GetItem(session.SessionId, session.CodeCampId);

                var response = new ServiceResponse <SessionInfo> {
                    Content = savedSession
                };

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