Username Checking & Changing Role Permissions

Jun 13, 2013 at 8:27 AM
Hi Mike

This is a great system - not too overwhelming - indeed I have also found it exceptionally useful as a 'learning' tool, seeing how you go about implementing solutions - thanks very much!

I have however come across a couple of issues, and have posted how I resolved them below - I don't know whether this is best practise according to the solution, but I thought I would post my findings.


I noticed that I wasn't getting the desired menu options when logged on as a different user - it transpired that the logon user name check, was case sensitive - as such I altered the below file to bring them all to a lower-case format (for checking purposes).

Permissions.cs

WHERE lower(Users.UserName) = @0";
permissions = db.Query(commandText, WebSecurity.CurrentUserName.ToLower()).Select(item => item.Name).Cast<string>();
I noticed that when you saved changes to a role permission that had "no" boxes ticked (a rare situation, I accept), it threw an error - as such I just put in a condition, confirming that the permissions post was not empty.

RolePermissions.cshtml

if (!Request["Permissions"].IsEmpty())
{
    foreach (var permission in Request["Permissions"].Split(','))
    {
        commandText = @"INSERT INTO RolesPermissions (RoleId, PermissionId) VALUES (@0, @1)";
        db.Execute(commandText, roleId, permission);
    }
}
Coordinator
Jun 13, 2013 at 9:46 AM
Thanks for your contributions. There is a fair amount of error checking that needs to be added to the system before it moves out of Alpha.