public virtual object EditUser([FromBody] NewUser editedUser)
 {
     //Need to set clients somehow
     using (var dbConnection = new SysDB())
     {
         var targetUserId = dbConnection.GetTable <SysUser>().First(user => user.Email == editedUser.Email).UserID;
         dbConnection.GetTable <SysUser>().Where(user => user.UserID == targetUserId)
         .Set(user => user.FirstName, user => editedUser.firstName)
         .Set(user => user.LastName, user => editedUser.lastName)
         .Set(user => user.UpdatedOn, user => DateTime.Now)
         .Update();
         dbConnection.GetTable <SysUserrole>().Where(userrole => userrole.UserID == targetUserId)
         .Set(userrole => userrole.RoleID, userrole => dbConnection.SysRole
              .First(role => role.RoleName == editedUser.role).RoleID)
         .Set(userrole => userrole.UpdatedOn, userrole => DateTime.Now)
         .Update();
     }
     return(new OkObjectResult("User updated"));
 }
        public virtual object DeleteUser(int userId)
        {
            string targetUserEmail = null;

            using (var dbConnection = new SysDB())
            {
                targetUserEmail = dbConnection.GetTable <SysUser>().First(user => user.UserID == userId).Email;
                dbConnection.GetTable <SysUserrole>()
                .Where(userrole => userrole.UserID == userId)
                .Delete();
                dbConnection.GetTable <SysUser>()
                .Where(user => user.UserID == userId)
                .Delete();
            }

            var targetAuth0UserId = new ManagementApiClient().GetUsers().First(auth0User => auth0User.Email == targetUserEmail).UserId;

            new ManagementApiClient().DeleteUser(targetAuth0UserId);
            return(new OkObjectResult("User deleted"));
        }
예제 #3
0
        public static List <T> GetList <T>(string filter) where T : class
        {
            using (var db = new SysDB())
            {
                var query = from x in db.GetTable <T>()
                            select x;

                if (filter.Length > 0)
                {
                    query = query.Where(filter);
                }

                return(query.ToList <T>());
            }
        }
예제 #4
0
        public static T GetModel <T>(string filter) where T : class
        {
            using (var db = new SysDB())
            {
                var query = from x in db.GetTable <T>()
                            select x;

                if (filter.Length > 0)
                {
                    query = query.Where(filter);
                }

                return(query.FirstOrDefault <T>());
            }
        }