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

Activities of "aaron"

Answer

You can override SaveChanges and SaveChangesAsync in YourDbContext:

public override int SaveChanges()
{
    try
    {
        return base.SaveChanges();
    }
    catch (DbUpdateConcurrencyException innerException)
    {
        throw new UserFriendlyException("Concurrency exception!", innerException.Message, innerException);
    }
}

Remove CreationTime and CreatorUserId from TestDetailsDto.

If you want a workaround:

var classobj = _someService.GetEntity(input.id);
input.CreationTime = classobj.CreationTime;
input.CreatorUserId = classobj.CreatorUserId;
ObjectMapper.Map(input, classobj);

Yes, it's good to have unique names.

Just in case you want the same name, here's the workaround that's hinted in the error log: #4095@05916f9a-3cd2-40f0-9c12-072cb50f0507

Can you show the error log?

Can you show a screenshot and the error log?

Try this:

public async Task CreateObj(ObjListDto input)
{
    string username;
    using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.Suppress)
    {
        username = GetCurrentUser().UserName;
        uow.Complete();
    }
    var obj = ObjectMapper.Map<Obj>(input);
    obj.Username = username;
    await _objRepository.InsertAsync(obj);
}

Actions require an explicit HttpMethod binding for Swagger

Add [HttpGet] attributes to your routes.

Can you show the error log?

Pass in the proper connection string to UseSqlServer.

You know it's solved, but you refuse to use the solution?

Answer
  1. Add CreatorUserName and LastModifierUserName:
public class MyFullAuditedEntity : FullAuditedEntity
{
    public string CreatorUserName { get; set; }

    public string LastModifierUserName { get; set; }
}
  1. Subclass ClaimsAbpSession:
public class MyClaimsAbpSession : ClaimsAbpSession
{
    public string UserName => PrincipalAccessor.Principal?.Claims.FirstOrDefault(c => c.Type == AbpClaimTypes.UserName);
}
  1. Replace service in PreInitialize method of YourCoreModule:
Configuration.ReplaceService<IAbpSession, MyClaimsAbpSession>();
  1. Override methods in YourDbContext:
protected override void SetCreationAuditProperties(object entityAsObj, long? userId)
{
    base.SetCreationAuditProperties(entityAsObj, userId);

    var myFullAuditedEntity = entityAsObj as MyFullAuditedEntity;
    if (myFullAuditedEntity != null) {
        myFullAuditedEntity.CreatorUserName = AbpSession.As<MyClaimsAbpSession>().UserName;
    }
}

protected override void SetModificationAuditProperties(object entityAsObj, long? userId)
{
    base.SetModificationAuditProperties(entityAsObj, userId);

    var myFullAuditedEntity = entityAsObj as MyFullAuditedEntity;
    if (myFullAuditedEntity != null) {
        myFullAuditedEntity.LastModifierUserName = AbpSession.As<MyClaimsAbpSession>().UserName;
    }
}
Showing 1311 to 1320 of 1543 entries