Base solution for your next web application

Activities of "gpcaretti"

Question

Dear All, I had the same issue shown here: UserRole topic and solved in a similar way with the payload of writing complex code.

My question is: Why don't you add a reference to Roles in UserRole class?

I post here your original code for UserRole with my little suggestion:

public class UserRole : CreationAuditedEntity<long>, IMayHaveTenant
{
        public virtual int? TenantId { get; set; }
        public virtual long UserId { get; set; }
        public virtual int RoleId { get; set; }

       // my suggestion
        [ForeignKey("RoleId")]
        public virtual Role Role { get; set; }

       public UserRole()
        {
        }

        public UserRole(int? tenantId, long userId, int roleId)
        {
            TenantId = tenantId;
            UserId = userId;
            RoleId = roleId;
        }     
}
Question

During this new tragedy my heart goes out to all the victims and Turkish people. Stay strong, Gianpiero

As you know, no validation code is required for validating input Dtos in Application Services, as it is automatically done by the framework, possibly calling custom validation too.

Is there a way to define a similar mechanism before returning the output Dto? I'd like to filter the Dto by blanking some values according to current AbpSession user and I'd like to do it outside the application service method.

I am sure it is possible, but I sincerely do not know how to realize it.

I have been using the AngularJs SPA template.

Thank you for your help, Gianpiero

Let's have a some business method returning users details:

public async Task<MyUserDto>  getUserInfo(int id);
... and other similar methods...

And Let's suppose I want to return some sensible information about the user only to specific users (e.g. having view.full.info permission)

Where do you think it is the best way where to hide these info?

  1. Into every method?
  2. Into the returning MyUserDto?
  3. Elsewhere?

I'd working on MyUserDto by implementing the ICustomValidate interface where I check the current user in session and null the sensible information according to its permissions.

But I am not sure...

tnx for your help! Gp

Hi, I am trying to implement a method into a service that create a user and then assign a role to it.

The problem is that to assign the role, I need the User.Id of the created user and I have not it but any FindBy into the same transaction return null due to the fact (I think) I am into the unit of work:

public class UserAppService : MyNewHouseAppServiceBase, IUserAppService {
  // ....
 public async Task CreateAdmin(CreateUserInput input) {
        var user = input.MapTo<User>();
       (await UserManager.CreateAsync(user)).CheckErrors(LocalizationManager);

       var u = await UserManager.FindByNameAsync(input.UserName); // <-- this returns null!!!
       (await UserManager.AddToRoleAsync(u.Id, StaticRoleNames.Tenants.Admin)).CheckErrors(LocalizationManager);
   }
}

I can I get the user.Id by staying into the unit of work? I wish to have the operation all transaction.

Tnx gp

I am newbie of ASP.NET BoilerPlate (ABP) and I am trying to understand how to create custom mappings using AutoMapper.

if I have two classes like the following where I want the property AB to be automapped as a join of A and B:

[AutoMapTo(typeof(DestClass)]  // <= do I need it for this case?
public class SourceClass {
    public string A { get; set; }
    public string B { get; set; }
}

public class DestClass {
    public string AB { get; set; }
}

I image I have to init automapper properly by using this kind of code:

Mapper.CreateMap<SourceClass, DestClass>()
    .ForMember(dest => dest.AB,
        opts => opts.MapFrom(src => (src.A + ", " + src.B)));

My question is: As I am in my web module and the classes are used by my AppService, where do I place the automapper init code above? Also, do I need to decorate the classes with the [AutoMap] attrib (I think, no)?

Thank you

Showing 1 to 6 of 6 entries