Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "sbenfares"

Thanks it works !

PS : Awesome support for ANZ :)

Thanks

Hi,

In my app, i'm using SessionCache LoginInformation ViewModel in my layout view to display the user.surname.

I have a form for updating the surname if needed, how can i update the SessionCache LoginInformation after posting my form ?

Because now it keeps the cached value, and it's different from my database value.

Thanks

I used the LoginInformations field in the HeaderViewModel, which contains exactly what i need.

No need for the variable in page, best use with the ViewModel.

Thanks for your help.

Hi,

I would like to center the div/canvas displayed in the modal when changing the profile picture in the ChangeProfilePicture Modal.

I can't figure how to do this, what element should i modify in Jcrop or in the modal...

Thanks!

PS : You can see the capture attached

Capture.PNG

The name 'loginInfo' does not exist in the current context

I would like to get FirstName and LastName of my users in my chstml views.

With asp.net identity we can have @User.identity.Name but only the name is exposed.

What is the cleanest method to get User.FirstName & Lastname (& other properties) in ANZ ?

Question

Hi,

I need to handle 2 (or more) types of Users in my application (Example Teacher & Students) Each user wil have common properties (defined in User Table) and have specific fields.

What is the best approach for integrate this with ANZ ?

PS : In my previous application i used Asp.net Identity 2.0 table AspNetUser and Created 2 specific tables : Student & Teacher. On AspNetUser i created a nullable Foreign Key to Student and Teacher table. I followed this recommandation : https://stackoverflow.com/questions/27059017/creating-inheritance-users-from-base-asp-net-identity-user

Then to retrieve Student data i used User.Student.Name

Is that a good practice for you ? Should i use the same method for ANZ and AbpUsers Table ? How can i add StudentId and TeacherId in AbpSession in ANZ ?

Thanks !

You are right it's working without UserManager, it was a missing tenantId that caused my problem.

:D Thanks !

PS : And yes i learned why we should replace XXXX.Result by await thanks to ([https://stackoverflow.com/questions/24623120/await-on-a-completed-task-same-as-task-result])) :ugeek:

OK so there was 2 problems here :

1 - The _userManager.IsInRole was not working when i created a user in SeedHelper. To correct this i injected UserManager in SeedHelper and pass it to TenantRoleAndUserBuilder.

public static class SeedHelper
    {
       private static UserManager UserManager { get; set; }

        public static void SeedHostDb(IIocResolver iocResolver)
        {
            UserManager = iocResolver.Resolve<UserManager>();
            WithDbContext<PlatformDbContext>(iocResolver, SeedHostDb);
        }

        public static void SeedHostDb(PlatformDbContext context)
        {
            context.SuppressAutoSetTenantId = true;

            //Host seed
            new InitialHostDbBuilder(context).Create();

            //Default tenant seed (in host database).
            new DefaultTenantBuilder(context).Create();
            new TenantRoleAndUserBuilder(context, 1, UserManager).Create();
       }

....

}

Then in TenantRoleAndUserBuilder i've added a UserManager readonly field and get it from the constructor. Then in the CreateUser method, i replaced :

//Assign Admin role to admin user
                _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id));
                _context.SaveChanges();

by

//Assign role to user
            _userManager.AddToRoleAsync(user, role.Name).Wait();

Then the _userManager.IsInRole is working now in the AccountController for my users created in SeedHelper.

2 - The second problem was to handle properly the url changes depending on the roles of users.

In the home controller in the Index method i've done this :

var homeUrl = HomeUrlForUser();

            return AbpSession.UserId.HasValue ? 
                RedirectToAction("Index", "Home", new { area = homeUrl }) : 
                RedirectToAction("Login", "Account");

Then i created a HomeUrlForUser method :

private string HomeUrlForUser()
        {
            if (User.IsInRole(StaticRoleNames.Tenants.Candidat)) return "Candidat";
            return User.IsInRole(StaticRoleNames.Tenants.Employeur) ? "Employeur" : "Admin";
        }

In the account controller i've created a method :

private string CheckReturnUrlForRole(string returnUrl, string userNameOrEmailAddress)
        {
            var user = _userManager.FindByNameOrEmailAsync(userNameOrEmailAddress).Result;
            var isEmployeur = _userManager.IsInRoleAsync(user, StaticRoleNames.Tenants.Employeur).Result;
            var isCandidat = _userManager.IsInRoleAsync(user, StaticRoleNames.Tenants.Candidat).Result;

            if (isEmployeur) return returnUrl.Replace("Admin", "Employeur");
            return isCandidat ? returnUrl.Replace("Admin", "Candidat") : returnUrl;
        }

And then in the login method add a call to this CheckReturnUrlForRole function just after GetLoginResultAsync call :

var loginResult = await GetLoginResultAsync(loginModel.UsernameOrEmailAddress, loginModel.Password, GetTenancyNameOrNull());
returnUrl = CheckReturnUrlForRole(returnUrl, loginModel.UsernameOrEmailAddress);

Don't know if this is optimal but it works, and i hope it will help someone having same needs.

Showing 41 to 50 of 53 entries