// POST api/users/getSelf public UserGeneral GetSelf([FromBody] string value) { // Check user is logged in string returnValue = "fail"; try { using (var ctx = new PamProjectEntities2()) { UserGetList postUser = JsonConvert.DeserializeObject <UserGetList>(value); //Is session active? var userSession = ctx.activeSessions.SqlQuery("SELECT * FROM activeSessions WHERE sessionToken LIKE '" + postUser.SessionKey + "';").FirstOrDefault <activeSession>(); if (userSession.expireTime >= DateTime.Now) { // Return there own user details UserGeneral self = ctx.Database.SqlQuery <UserGeneral>("SELECT * FROM users WHERE userId = " + userSession.userId + ";").FirstOrDefault <UserGeneral>(); //returnValue = JsonConvert.SerializeObject(self); return(self); } } } catch (Exception e) { returnValue = "Failed! - Exception - " + e; } //return returnValue; return(new UserGeneral()); }
public List <UserGeneral> GetAll([FromBody] string value) { //Get the information from the application List <UserGeneral> returnValue = new List <UserGeneral>(); try { using (var ctx = new PamProjectEntities2()) { UserGetList postUser = JsonConvert.DeserializeObject <UserGetList>(value); //Is session active? var userSession = ctx.activeSessions.SqlQuery("SELECT * FROM activeSessions WHERE sessionToken LIKE '" + postUser.SessionKey + "';").FirstOrDefault <activeSession>(); if (userSession.expireTime >= DateTime.Now) { //Is user admin? var accessUser = ctx.users.SqlQuery("SELECT * FROM users WHERE userId LIKE '" + userSession.userId + "';").FirstOrDefault <user>(); if (accessUser.permissionLevelId == 1 || accessUser.permissionLevelId == 2) { //Return Json List of users List <UserGeneral> userList = new List <UserGeneral>(); userList = ctx.Database.SqlQuery <UserGeneral>("SELECT * FROM users").ToList(); returnValue = userList; } } } } catch (Exception e) { //returnValue = "Failed! - Exception - " + e; } return(returnValue); }
public string GetAll([FromBody] string value) { //Get the information from the application string returnValue = "fail"; try { using (var ctx = new PamProjectEntities2()) { UserGetList postUser = JsonConvert.DeserializeObject <UserGetList>(value); //Is session active? var userSession = ctx.activeSessions.SqlQuery("SELECT * FROM activeSessions WHERE sessionToken LIKE '" + postUser.SessionKey + "';").FirstOrDefault <activeSession>(); if (userSession.expireTime >= DateTime.Now) { //Return Json List of users List <serverO> userList = new List <serverO>(); userList = ctx.Database.SqlQuery <serverO>("SELECT * FROM serverOs").ToList(); returnValue = JsonConvert.SerializeObject(userList); } } } catch (Exception e) { returnValue = "Failed! - Exception - " + e; } return(returnValue); }