public HttpResponseMessage DeleteTrack(int itemId, int codeCampId) { try { var sessions = SessionDataAccess.GetItemsByTrackId(itemId, codeCampId); if (sessions.Any()) { foreach (var session in sessions) { session.TrackId = null; session.LastUpdatedByDate = DateTime.Now; session.LastUpdatedByUserId = UserInfo.UserID; SessionDataAccess.UpdateItem(session); } } TrackDataAccess.DeleteItem(itemId, codeCampId); 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 AssignSessionToTrack(int sessionId, int trackId, int codeCampId) { try { var session = SessionDataAccess.GetItem(sessionId, codeCampId); session.TrackId = trackId; 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)); } }
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 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)); } }