How to assign role to linq queries?
-
Dear all, I am writing to seek assistant, in how do I assign my queries below to specific roles. I am currently not storing my roles for any user in my db server. Is this task still plausible? Can this task by done using either using 'string array' roles (i.e.
string[] userRoles = new string[] { "full", "trial" }
), or using 'Group By' function in linq qeuery?public bool full(string username, string password)
{
//define the query : query will be an IQueryable
var query = // query// "execute" the query return query.FirstOrDefault() != null; } public bool trial(string username, string password) { //define the query : query will be an IQueryable var query = // query // "execute" the query return query.FirstOrDefault() != null; }
Many thanks for help and time.
-
Dear all, I am writing to seek assistant, in how do I assign my queries below to specific roles. I am currently not storing my roles for any user in my db server. Is this task still plausible? Can this task by done using either using 'string array' roles (i.e.
string[] userRoles = new string[] { "full", "trial" }
), or using 'Group By' function in linq qeuery?public bool full(string username, string password)
{
//define the query : query will be an IQueryable
var query = // query// "execute" the query return query.FirstOrDefault() != null; } public bool trial(string username, string password) { //define the query : query will be an IQueryable var query = // query // "execute" the query return query.FirstOrDefault() != null; }
Many thanks for help and time.
The best practice is to store role in db but you can also store in dictionary
-
The best practice is to store role in db but you can also store in dictionary
Thank you so much for your response. Is their a way to group or name the queries, so i can compute the following logic:
if (user & password match from full query)
{
return string = "full status"
}
else
{
return string = "trial status"
}Is their some function or framework i could look into. please help. Thank you
-
Thank you so much for your response. Is their a way to group or name the queries, so i can compute the following logic:
if (user & password match from full query)
{
return string = "full status"
}
else
{
return string = "trial status"
}Is their some function or framework i could look into. please help. Thank you
You can simply use switch case. Or its better if you can share your both the queries.
-
You can simply use switch case. Or its better if you can share your both the queries.
Hi, thank you for your reply back and you suggestion on 'switch back'. I will look into this function. Currently this what my queries look like:
public User trial(string username, string password)
{
string[] roles = new string[] { "trial"};
var query = from s in db.Subs
join u in db.Cust on s.sUID equals u.uID
where s.sExpiryDate >= DateTime.Now &&
u.uUsername == username &&
u.uPassword == password
select u;
return query.FirstOrDefault();
}public User full(string username, string password) { string\[\] roles = new string\[\] { "full"}; var query = from s in db.Subs join u in db.Cust on s.sUID equals u.uID u.uUsername == username && u.uPassword == password select u; return query.FirstOrDefault(); }
Any help or suggestion, would be really appreciated. Thanks in advance.