Base solution for your next web application
Open Closed

Why can't update the CreatorUserId and LastModifierUserId ? #919


User avatar
0
winson created

I inherit IModificationAudited and ICreationAudited interface and create CreatorUserId and LastModifierUserId fields, but when I insert a record, I have set the value to these fields like below:

var item = new Item
{
    Active = true,
    Name = input.Name,
    Value = input.Value,
    CreationTime = DateTime.Now,
    LastModificationTime = DateTime.Now,
    CreatorUserId = 1, //TODO: for testing
    LastModifierUserId = 1
};

_itemRepository.Insert(item);

but this just can save the LastModifierUserId value, and the CreatorUserId is null, if the LastModifierUserId is null, when I do the update, I also can't update it:

var item = _itemRepository.Get(input.Id);
            
item.Name = input.Name;
item.Value = input.Value;
item.LastModificationTime = DateTime.Now;
item.LastModifierUserId = 1; //TODO: for testing

_itemRepository.Update(item);

after that, the LastModifierUserId is also null.

I have created the ForeignKey for these fields :

public long? LastModifierUserId { get; set; }

public long? CreatorUserId { get; set; }

[ForeignKey("CreatorUserId")]
public virtual AdminUser CreatorUser { get; set; }

[ForeignKey("LastModifierUserId")]
public virtual AdminUser LastModifierUser { get; set; }

2 Answer(s)
  • User Avatar
    0
    winson created

    anyone can help?

    thanks!!!!

  • User Avatar
    0
    winson created

    ok, I have solved this issue, because I didn't use the zero-module, so the framework can't get the user id from abpsession, after I review the source code, I know just need to override SetCreationAuditProperties this method and can solve my problem....