且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为查询分配角色

更新时间:2023-02-26 08:09:10

如果你没有每个用户的角色字段,你将如何确定用户所属的角色?

Dear all,

i am writing to seek help, in how do i assign a single role to following query using 'string array []':

Updated query code:

   public UserDetail trial(string username, string password)
{

    string[] Role = new string[] { "trial"};


    var query = (from s in db.Subs
                join u in db.UserDetails on s.sUID equals u.uID
                where s.sExpiryDate >= DateTime.Now &&
                u.uUsername == username &&
                u.uPassword == password
                select u).FirstOrDefault();

    if (query != null)
    {
        // Build a user and add the appropriate Trial role
        return new UserDetail() { username = query.uUsername, password = query.uPassword, Role = "Trial" };
    }
    else
    {
        // No user was found
        return null;
    }

}



I am currently having issue with defining the parameters such as username, password and role, and its outputting compiling error of 'does not contain definition for username' If anyone could advise on this issue, it would be very much appreciated.

Please note, i do not have role field setup in my database server.

Many thanks

If you don't have a role field for each user, how are you going to determine which role(s) a user is a part of??