Skip to content

Commit

Permalink
feat: adding log
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarmesquita committed Sep 2, 2024
1 parent bc155d6 commit 36dd5fa
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/Api.Crud.Client/Api.Crud.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<RootNamespace>eQuantic.Core.Api.Crud.Client</RootNamespace>
<AssemblyName>eQuantic.Core.Api.Crud.Client</AssemblyName>
<AssemblyTitle>eQuantic.Core.Api.Crud.Client</AssemblyTitle>
<AssemblyVersion>1.7.12.0</AssemblyVersion>
<FileVersion>1.7.12.0</FileVersion>
<Version>1.7.12.0</Version>
<AssemblyVersion>1.7.13.0</AssemblyVersion>
<FileVersion>1.7.13.0</FileVersion>
<Version>1.7.13.0</Version>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>

<PackageId>eQuantic.Core.Api.Crud.Client</PackageId>
Expand Down
6 changes: 3 additions & 3 deletions src/Api.Crud/Api.Crud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<AssemblyName>eQuantic.Core.Api.Crud</AssemblyName>
<RootNamespace>eQuantic.Core.Api.Crud</RootNamespace>
<AssemblyTitle>eQuantic.Core.Api.Crud</AssemblyTitle>
<AssemblyVersion>1.7.12.0</AssemblyVersion>
<FileVersion>1.7.12.0</FileVersion>
<Version>1.7.12.0</Version>
<AssemblyVersion>1.7.13.0</AssemblyVersion>
<FileVersion>1.7.13.0</FileVersion>
<Version>1.7.13.0</Version>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>

<PackageId>eQuantic.Core.Api.Crud</PackageId>
Expand Down
6 changes: 3 additions & 3 deletions src/Application.Crud/Application.Crud.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
<RootNamespace>eQuantic.Core.Application.Crud</RootNamespace>
<AssemblyName>eQuantic.Core.Application.Crud</AssemblyName>
<AssemblyTitle>eQuantic.Core.Application.Crud</AssemblyTitle>
<AssemblyVersion>1.7.12.0</AssemblyVersion>
<FileVersion>1.7.12.0</FileVersion>
<Version>1.7.12.0</Version>
<AssemblyVersion>1.7.13.0</AssemblyVersion>
<FileVersion>1.7.13.0</FileVersion>
<Version>1.7.13.0</Version>
<TargetFrameworks>netstandard2.1;net7.0;net8.0</TargetFrameworks>

<PackageId>eQuantic.Core.Application.Crud</PackageId>
Expand Down
47 changes: 37 additions & 10 deletions src/Application.Crud/Services/CrudServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,18 @@ public virtual async Task<TKey> CreateAsync(CreateRequest<TRequest> request, Can
var userId = await ApplicationContext.GetCurrentUserIdAsync();
itemWithOwner.CreatedById = userId;
}

await Repository.AddAsync(item);
await Repository.UnitOfWork.CommitAsync(cancellationToken);

try
{
await Repository.AddAsync(item);
await Repository.UnitOfWork.CommitAsync(cancellationToken);
}
catch (Exception ex)
{
Logger.LogError(ex, "One error was occurred when creating '{EntityName}'", typeof(TEntity).Name);
throw;
}

await OnAfterCreateAsync(request, item, cancellationToken);

return item.GetKey();
Expand Down Expand Up @@ -91,8 +100,17 @@ public virtual async Task<bool> UpdateAsync(UpdateRequest<TRequest, TKey> reques
itemWithTrack.UpdatedById = userId;
}

await Repository.ModifyAsync(item);
await Repository.UnitOfWork.CommitAsync(cancellationToken);
try
{
await Repository.ModifyAsync(item);
await Repository.UnitOfWork.CommitAsync(cancellationToken);
}
catch (Exception ex)
{
Logger.LogError(ex, "One error was occurred when updating '{EntityName}'", typeof(TEntity).Name);
throw;
}

await OnAfterUpdateAsync(request, item, cancellationToken);

return true;
Expand Down Expand Up @@ -126,16 +144,25 @@ public virtual async Task<bool> DeleteAsync(ItemRequest<TKey> request, Cancellat
itemWithHistory.DeletedById = userId;
}

if (softDelete)
try
{
await Repository.ModifyAsync(item);
if (softDelete)
{
await Repository.ModifyAsync(item);
}
else
{
await Repository.RemoveAsync(item);
}

await Repository.UnitOfWork.CommitAsync(cancellationToken);
}
else
catch (Exception ex)
{
await Repository.RemoveAsync(item);
Logger.LogError(ex, "One error was occurred when deleting '{EntityName}'", typeof(TEntity).Name);
throw;
}

await Repository.UnitOfWork.CommitAsync(cancellationToken);
await OnAfterDeleteAsync(item, cancellationToken);

return true;
Expand Down

0 comments on commit 36dd5fa

Please sign in to comment.