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

Losing CreatorUserId on Update #5100


User avatar
0
arminm created

Hi, Perhaps someone can tell me why this would occur.

The CreatorUserId on Update is getting set as NULL, which previously wasn't the case. So I've put in a little bit of a workaround:

private async Task Update(CreateOrEditGroupDto input)
         {
            var group = await _groupRepository.FirstOrDefaultAsync((int)input.Id);
            var x = ObjectMapper.Map(input, group);
            
            // replace creatoruserid hack because it's gone missing
            x.CreatorUserId = AbpSession.UserId;
            await _groupRepository.UpdateAsync(x);
        }

The Create works fine still.

So it's not critical as the workaround is in place, however, I was just wondering if someone had seen this before and perhaps let me know where I have borked it.

Thanks for looking


7 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Does CreateOrEditGroupDto have a CreatorUserId property that is null?

  • User Avatar
    0
    arminm created

    Here is the Dto:

    As it's derived from FullAuditedEntityDto, shouldn't it include the populated property?

    public class CreateOrEditGroupDto : FullAuditedEntityDto<int?>
        {
    		[Required]
    		public string Name { get; set; }		
    		
    		public string Description { get; set; }
    
            //public Collection<ContactDto> Contacts { get; set; }
    
        }
    
    public async Task<GetGroupForEditOutput> GetGroupForEdit(EntityDto input)
             {
                var group = await _groupRepository.FirstOrDefaultAsync(input.Id);
                var output = new GetGroupForEditOutput {Group = ObjectMapper.Map<CreateOrEditGroupDto>(group)};
    
    			
    			
                return output;
             }
    
  • User Avatar
    0
    aaron created
    Support Team

    It is populated in output, but did you populate it in input?

    Consider using a CreateOrEditGroupInput that does not inherit FullAuditedEntityDto.

  • User Avatar
    0
    arminm created

    If it doesn't inherit from FullAuditedEntityDto, then would it automatically add the CreatorUserId on save/update?

    so, essentially what you are saying is that because CreatorUserId exists and is NULL, it's getting overwritten? and that if it doesn't exist in the "input" Dto, then the CreatorUserId will be populated on save?

  • User Avatar
    0
    aaron created
    Support Team

    Yes, yes, and yes.

  • User Avatar
    0
    arminm created

    Awesome, thanks! clarity makes sense

  • User Avatar
    0
    aaron created
    Support Team

    That's great :)