internal void Add(Session session)
 {
     using (var dbContext = new MedialynxDbSessionContext()) {
         dbContext.Sessions.Add(session);
         dbContext.SaveChanges();
     }
 }
        public Session Get(string sessionId)
        {
            Guid id = Utils.ToGuid(sessionId, false);

            using (var dbContext = new MedialynxDbSessionContext()) {
                if (id != Guid.Empty)
                {
                    string sid = id.ToString("B");
                    return(dbContext.Sessions.FirstOrDefault(session => session != null && session.Id == sid));
                }
            }
            return(null);
        }
 internal void Delete(string userId)
 {
     using (var dbContext = new MedialynxDbSessionContext()) {
         Guid id = Utils.ToGuid(userId);
         if (id != Guid.Empty)
         {
             string sid = id.ToString("B");
             IEnumerable <Session> sessions = dbContext.Sessions.Where(session => session != null && session.Id == sid);
             dbContext.Sessions.RemoveRange(sessions);
             dbContext.SaveChanges();
         }
     }
 }
 internal void Update(Session session)
 {
     using (var dbContext = new MedialynxDbSessionContext()) {
         Session existsSession = dbContext.Sessions.FirstOrDefault(s => s != null && s.Id == session.Id);
         if (existsSession != null)
         {
             if (Utils.CopyPropertyValues <Session>(session, existsSession))
             {
                 dbContext.Sessions.Update(existsSession);
                 dbContext.SaveChanges();
             }
         }
     }
 }
 public User GetBySession(string sessionId)
 {
     using (var dbContext = new MedialynxDbSessionContext()) {
         Session session = dbContext.Sessions.FirstOrDefault(s => s != null && s.Id == sessionId);
         if (session != null)
         {
             Guid id = Utils.ToGuid(session.UserId);
             using (var dbUserContext = new MedialynxDbUserContext()) {
                 if (id != Guid.Empty)
                 {
                     string sid  = id.ToString("B");
                     User   user = dbUserContext.Users.FirstOrDefault(user => user != null && user.Id == sid);
                     return(user);
                 }
             }
         }
     }
     return(null);
 }