예제 #1
0
 public void UpdateSessionLastAction() {
   using (JolTudomEEntities ent = new JolTudomEEntities()) {
     ent.Attach(_Session);
     _Session.LastAction = DateTime.UtcNow;
     ent.SaveChanges();
   }
 }
예제 #2
0
 public void DeleteSession() {
   using (JolTudomEEntities ent = new JolTudomEEntities()) {
     ent.Attach(_Session);
     ent.Sessions.DeleteObject(_Session);
     ent.SaveChanges();
   }
 }
예제 #3
0
 private void GetSession() {
   using (JolTudomEEntities ent = new JolTudomEEntities()) {
     _Session = ent.Sessions.FirstOrDefault(s => s.Token == _Token);
     if (_Session != null) {
       ent.Sessions.Detach(_Session);
     }
     else {
       throw new SessionNotAvailable();
     }
   }
 }
예제 #4
0
    public List<TestDetails> GetTestDetails(string token, int testid, int? personid) {
      SessionManager sm = new SessionManager(token);

      JolTudomEEntities ent = new JolTudomEEntities();
      List<TestDetails> testdet = new List<TestDetails>();

      var details = ent.usp_Eval(testid, personid ?? sm.Session.PersonID, sm.Session.PersonID, sm.Session.RoleID);
      testdet = details.ToList();
      sm.UpdateSessionLastAction();

      return testdet;
    }
예제 #5
0
    public List<Statistics> GetStatistics(string token, int? personid) {
      SessionManager sm = new SessionManager(token);

      JolTudomEEntities ent = new JolTudomEEntities();
      List<Statistics> statofperson = new List<Statistics>();

      var statistics = ent.usp_Statistics(personid ?? sm.Session.PersonID, sm.Session.PersonID, sm.Session.RoleID);
      statofperson = statistics.ToList();
      sm.UpdateSessionLastAction();

      return statofperson;
    }
예제 #6
0
    public string Login(string username, string password, out PersonDetails loggedinuser) {

      string token = string.Empty;

      try {
        JolTudomEEntities ent = new JolTudomEEntities();
        var loggedin = ent.usp_Authenticate(username, password);
        loggedinuser = loggedin.First();

        SessionManager sm = SessionManager.NewSession(loggedinuser);
        return sm.Session.Token;
      }
      catch (EntityCommandExecutionException) {
        // send only a general error message
        throw new Exception("Hibás felhasználónév vagy jelszó!");
      }

    }
예제 #7
0
    public static SessionManager NewSession(PersonDetails loggedinuser) {
      // generate a token
      // this could be more secure ...
      byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
      byte[] key = Guid.NewGuid().ToByteArray();
      string token = Convert.ToBase64String(time.Concat(key).ToArray());

      using (JolTudomEEntities ent = new JolTudomEEntities()) {
        // delete those sessions, which are dead - over of the given timeout
        ent.usp_SessionsCleanup(Settings.Default.SessionTimeoutMinute);

        // delete those tests, which are not completed
        ent.usp_CleanupTests(Settings.Default.MaxTestExecutionHour);

        // this must be saved to the database with the timestamp
        ent.Sessions.AddObject(new Session { Token = token, PersonID = loggedinuser.PersonID, RoleID = loggedinuser.RoleID, LastAction = DateTime.UtcNow });
        ent.SaveChanges();
      }

      SessionManager sm = new SessionManager(token);
      return sm;
    }
예제 #8
0
    /// <summary>
    /// we must provide the personid here, though in a normal case we could get that from session
    /// but if the session is over we don't have that
    /// </summary>
    /// <param name="token"></param>
    /// <param name="testid"></param>
    /// <param name="personid"></param>
    public void CancelTest(string token, int testid, int personid) {
      SessionManager sm;
      try {
        sm = new SessionManager(token);
      }
      catch (SessionNotAvailable) {
        // this is a special case that in the meantime the session is timed out
        // but the started test must be cancelled
        using (JolTudomEEntities ents = new JolTudomEEntities()) {
          ents.usp_CancelTest(testid, personid);
        }
        // and throw the exception to the client
        throw;
      }

      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        ent.usp_CancelTest(testid, personid);
        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }
    }
예제 #9
0
    public List<Courses> GetCourses(string token) {
      SessionManager sm = new SessionManager(token);

      List<Courses> courselist = new List<Courses>();
      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        var courses = ent.usp_GetCourses();
        courselist = courses.ToList();

        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }

      return courselist;
    }
예제 #10
0
    public void EditTopic(string token, int courseid, int topicid, string name, string description) {
      SessionManager sm = new SessionManager(token);

      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        ent.usp_EditTopic(name, description, topicid, courseid);
        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }

    }
예제 #11
0
    public void AddNewCourse(string token, string name, string description) {
      SessionManager sm = new SessionManager(token);

      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        ent.usp_AddNewCourse(name, description);
        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }
    }
예제 #12
0
    public List<PersonDetails> GetUsers(string token, int? searchroleid) {
      SessionManager sm = new SessionManager(token);

      JolTudomEEntities ent = new JolTudomEEntities();
      List<PersonDetails> plist = new List<PersonDetails>();
      try {
        var persons = ent.usp_GetAllUsers(sm.Session.RoleID, searchroleid ?? null);
        plist = persons.ToList();

        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }

      return plist;
    }
예제 #13
0
    public void NewUser(string token, string username, string prefix, string lastname, string middlename, string firstname, string password, int roleid) {

      JolTudomERoles newuserrole = (JolTudomERoles)roleid;

      // if token is available, it means only administrator can create a new user
      if (!string.IsNullOrEmpty(token)) {
        SessionManager sm = new SessionManager(token);
        if (sm.Session.UserRole != JolTudomERoles.Admin) {
          throw new ApplicationException("Csak Adminisztrátor hozhat létre új felhasználót!");
        }
      }
      // if token is null, it means the new user will be student
      else {
        // force roleid to be a Student
        newuserrole = JolTudomERoles.Student;
      }

      // the rest of the validation will be performed in backend
      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        ent.usp_AddNewUser(username, prefix, lastname, middlename, firstname, password, (byte)newuserrole);
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }

    }
예제 #14
0
    public List<Topics> GetTopics(string token, int courseid) {
      SessionManager sm = new SessionManager(token);

      List<Topics> topiclist = new List<Topics>();
      JolTudomEEntities ent = new JolTudomEEntities();
      try {
        var topics = ent.usp_GetTopics(courseid);
        topiclist = topics.ToList();

        sm.UpdateSessionLastAction();
      }
      catch (EntityCommandExecutionException ece_exc) {
        throw ece_exc.InnerException;
      }

      return topiclist;
    }