public HttpResponseMessage GetSessionCountBySpeakerId(int codeCampId, int speakerId) { try { var allSessions = SessionDataAccess.GetItems(codeCampId); var sessionSpeakers = SessionSpeakerDataAccess.GetItemsBySpeakerId(speakerId).Select(s => s.SessionId); var sessions = allSessions.Where(s => sessionSpeakers.Contains(s.SessionId)); var response = new ServiceResponse <int> { Content = sessions.Any() ? sessions.Count() : 0 }; if (!sessions.Any()) { ServiceResponseHelper <int> .AddNoneFoundError("sessions", ref response); } return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }
public HttpResponseMessage CreateSession(SessionInfo session) { try { var timeStamp = DateTime.Now; session.CreatedByDate = timeStamp; session.CreatedByUserId = UserInfo.UserID; session.LastUpdatedByDate = timeStamp; session.LastUpdatedByUserId = UserInfo.UserID; if (session.TrackId == 0) { session.TrackId = null; } if (session.TimeSlotId == 0) { session.TimeSlotId = null; } // adding a date/time placeholder because DAL doesn't know how to handle a null value session.ApprovedByDate = Globals.NULL_DATE; SessionDataAccess.CreateItem(session); var sessions = SessionDataAccess.GetItems(session.CodeCampId); var savedSession = sessions.OrderByDescending(s => s.CreatedByDate).FirstOrDefault(s => s.Title == session.Title); 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)); } }
public HttpResponseMessage GetSessions(int codeCampId) { try { var sessions = SessionDataAccess.GetItems(codeCampId); var response = new ServiceResponse <List <SessionInfo> > { Content = sessions.ToList() }; if (sessions == null) { ServiceResponseHelper <List <SessionInfo> > .AddNoneFoundError("sessions", ref response); } return(Request.CreateResponse(HttpStatusCode.OK, response.ObjectToJson())); } catch (Exception ex) { Exceptions.LogException(ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ERROR_MESSAGE)); } }