//Create new session.
 #region
 public Boolean CreateNewSession(string username, Boolean responseStartSession)
 {
     if (!IsDoctor)
     {
         NoPermission("doctor/training/start");
         return(false);
     }
     else
     {
         Session client = Program.GetSessionWithUsername(username);
         if (client == null)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError("No client active with given username.")));
             return(false);
         }
         try
         {
             if (Database.AddActiveSession(username))
             {
                 dynamic answer = new
                 {
                     id   = "session/start",
                     data = new
                     {
                         status    = "OK",
                         sessionID = username
                     }
                 };
                 if (responseStartSession)
                 {
                     client.Send(JsonConvert.SerializeObject(answer));
                 }
                 return(true);
             }
             else
             {
                 Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError("Username already active. Other session has to be stopped first before starting a new one.")));
                 return(false);
             }
         }
         catch (Exception e)
         {
             Send(JsonConvert.SerializeObject(Commands.DoctorTrainingStartError(e.Message)));
             return(false);
         }
     }
 }
 //StartAstrand from patient
 #region
 public void StartAstrandFromPatient(string patientId)
 {
     try
     {
         Session clientToStart = Program.GetSessionWithUsername(patientId);
         if (clientToStart != null)
         {
             dynamic answer = new
             {
                 id   = "StartAstrand",
                 data = new
                 {
                     sessionId = patientId
                 }
             };
             clientToStart.Send(JsonConvert.SerializeObject(answer));
             dynamic answerToDocter = new
             {
                 id   = "Doctor/StartAstrand",
                 data = new
                 {
                     status = "ok"
                 }
             };
             Send(JsonConvert.SerializeObject(answerToDocter));
             Database.AddActiveSession(patientId);
         }
         else
         {
             Send(JsonConvert.SerializeObject(Commands.StartAstrandError("Patient not found")));
         }
     }
     catch (Exception e)
     {
         Send(JsonConvert.SerializeObject(Commands.StartAstrandError(e.Message)));
     }
 }