Ejemplo n.º 1
0
        public StdAcc GetAll([FromBody] string value)
        {
            //Get the information from the application
            StdAcc returnValue = new StdAcc();

            try
            {
                using (var ctx = new PamProjectEntities2())
                {
                    GetAccountForServer postUser = JsonConvert.DeserializeObject <GetAccountForServer>(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 account details
                        var reter = ctx.Database.SqlQuery <StdAcc>("SELECT * FROM standardAccount WHERE standardAccountId = " + postUser.Id).FirstOrDefault();
                        returnValue = reter;
                    }
                }
            }
            catch (Exception)
            {
                // returnValue = "Failed! - Exception - " + e;
            }
            return(returnValue);
        }
Ejemplo n.º 2
0
        public string Delete([FromBody] string value)
        {
            // check if the user is logged in and session is valid
            string returnValue = "fail";

            try
            {
                using (var ctx = new PamProjectEntities2())
                {
                    GetAccountForServer postUser = JsonConvert.DeserializeObject <GetAccountForServer>(value);
                    //Is session active?
                    var userSession = ctx.activeSessions.SqlQuery("SELECT * FROM activeSessions WHERE sessionToken LIKE '" + postUser.SessionKey + "';").FirstOrDefault <activeSession>();
                    if (userSession.expireTime >= DateTime.Now)
                    {
                        // check the user has permissions to add a user (Admin only)
                        var accessUser = ctx.users.SqlQuery("SELECT * FROM users WHERE userId LIKE '" + userSession.userId + "';").FirstOrDefault <user>();
                        if (accessUser.permissionLevelId == 1 || accessUser.permissionLevelId == 2)
                        {
                            // if both yes then run sql delete command on the ID passed into the controller.
                            ctx.Database.ExecuteSqlCommand("DELETE FROM standardAccount WHERE standardAccountId = " + postUser.Id + ";");
                            returnValue = "Pass!";
                        }
                    }
                }
            }
            catch (Exception e)
            {
                returnValue = "Failed! - Exception - " + e;
            }
            return(returnValue);
        }