public void DeleteItem(SessionInfo i)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<SessionInfo>();
         rep.Delete(i);
     }
 }
 public void DeleteItem(SessionInfo i)
 {
     repo.DeleteItem(i);
 }
 public void CreateItem(SessionInfo i)
 {
     repo.CreateItem(i);
 }
 private void UpdateSessionWithSpeakers(ref SessionInfo item)
 {
     item.Speakers = speakerRepo.GetSpeakersForCollection(item.SessionId, item.CodeCampId);
 }
 private void UpdateSessionWithRegistrantCount(ref SessionInfo item)
 {
     item.RegistrantCount = GetRegistrantCount(item.SessionId);
 }
 public void UpdateItem(SessionInfo i)
 {
     repo.UpdateItem(i);
 }
        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 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);
            }
        }