/// <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; } }
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; } }
public static SessionManager NewSession(int personid, int roleid) { // 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(JolTudomE_Api.Properties.Settings.Default.SessionTimeoutMinute); // delete those tests, which are not completed ent.usp_CleanupTests(JolTudomE_Api.Properties.Settings.Default.MaxTestExecutionHour); // this must be saved to the database with the timestamp ent.Sessions.Add(new Sessions { Token = token, PersonID = personid, RoleID = roleid, LastAction = DateTime.UtcNow }); ent.SaveChanges(); } SessionManager sm = new SessionManager(token); return(sm); }
public void UpdateSessionLastAction() { using (JolTudomEEntities ent = new JolTudomEEntities()) { ent.Attach(_Session); _Session.LastAction = DateTime.UtcNow; ent.SaveChanges(); } }
public void DeleteSession() { using (JolTudomEEntities ent = new JolTudomEEntities()) { ent.Attach(_Session); ent.Sessions.DeleteObject(_Session); ent.SaveChanges(); } }
public void UpdateSessionLastAction() { using (JolTudomEEntities ent = new JolTudomEEntities()) { //ent.Attach(_Session); _Session.LastAction = DateTime.UtcNow; ent.Entry(_Session).State = System.Data.Entity.EntityState.Modified; ent.SaveChanges(); } }
public void DeleteSession() { using (JolTudomEEntities ent = new JolTudomEEntities()) { //ent.Attach(_Session); ent.Sessions.Remove(_Session); ent.Entry(_Session).State = System.Data.Entity.EntityState.Deleted; ent.SaveChanges(); } }
private void GetSession() { using (JolTudomEEntities ent = new JolTudomEEntities()) { _Session = ent.Sessions.Include("Person").FirstOrDefault(s => s.Token == _Token); if (_Session == null) { throw new SessionNotAvailable(); } } }
public BaseController() { DBContext = new JolTudomEEntities(); CustomIdentity id = User.Identity as CustomIdentity; if (id != null) { SM = new SessionManager(id.Token); } }
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; } }
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); }
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; } }
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); }
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(); } } }
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ó!"); } }
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); }
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); }
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); }
private LoginResponse ValidateUser(string username, string password) { using (JolTudomEEntities db = new JolTudomEEntities()) { usp_Authenticate_Result result = db.usp_Authenticate(username, password).FirstOrDefault(); if (result != null) { var session = SessionManager.NewSession(result.PersonID, result.RoleID).Session; _Token = session.Token; _UserName = session.Person.UserName; return(new LoginResponse { PersonID = result.PersonID, RoleID = result.RoleID }); } else { return(null); } } }