Refactoring

This commit is contained in:
Andre Beging
2025-03-28 17:18:49 +01:00
parent 859b0c3712
commit e19268f3eb
4 changed files with 42 additions and 42 deletions

View File

@@ -38,7 +38,7 @@ namespace FoodsharingSiegen.Server.Data.Service
try
{
var targetProspect = await Context.Prospects!.Include(x => x.Interactions).FirstOrDefaultAsync(x => x.Id == interaction.ProspectID);
if (targetProspect == null) return new OperationResult<Interaction>(new Exception("Invalid prospect id"));
if (targetProspect == null) return new(new Exception("Invalid prospect id"));
interaction.ProspectID = Guid.Empty;
interaction.Created = DateTime.UtcNow;
@@ -53,11 +53,11 @@ namespace FoodsharingSiegen.Server.Data.Service
Context.Entry(targetProspect).State = EntityState.Detached;
Context.Entry(interaction).State = EntityState.Detached;
return new OperationResult<Interaction>(interaction);
return new(interaction);
}
catch (Exception e)
{
return new OperationResult<Interaction>(e);
return new(e);
}
}
@@ -74,7 +74,7 @@ namespace FoodsharingSiegen.Server.Data.Service
{
try
{
if (prospect == null) return new OperationResult<Prospect>(new Exception("Cannot be empty"));
if (prospect == null) return new(new Exception("Cannot be empty"));
prospect.Created = DateTime.UtcNow;
prospect.Id = Guid.Empty;
@@ -85,14 +85,14 @@ namespace FoodsharingSiegen.Server.Data.Service
if (saveR > 0)
{
await AuditService.Insert(AuditType.CreateProspect, prospect.Name, prospect.FsId.ToString());
return new OperationResult<Prospect>(prospect);
return new(prospect);
}
return new OperationResult<Prospect>(new Exception("Couldn't add prospect"));
return new(new Exception("Couldn't add prospect"));
}
catch (Exception e)
{
return new OperationResult<Prospect>(e);
return new(e);
}
}
@@ -118,11 +118,11 @@ namespace FoodsharingSiegen.Server.Data.Service
var prospects = await prospectsQuery.ToListAsync();
return new OperationResult<List<Prospect>>(prospects);
return new(prospects);
}
catch (Exception e)
{
return new OperationResult<List<Prospect>>(e);
return new(e);
}
}
@@ -139,16 +139,16 @@ namespace FoodsharingSiegen.Server.Data.Service
{
try
{
Context.Interactions!.Remove(new Interaction { Id = interactionId });
Context.Interactions!.Remove(new() { Id = interactionId });
await Context.SaveChangesAsync();
await AuditService.Insert(AuditType.RemoveInteraction, "?");
return new OperationResult();
return new();
}
catch (Exception e)
{
return new OperationResult(e);
return new(e);
}
}
@@ -166,7 +166,7 @@ namespace FoodsharingSiegen.Server.Data.Service
try
{
var entityProspect = await Context.Prospects!.FirstOrDefaultAsync(x => x.Id == prospect.Id);
if (entityProspect == null) return new OperationResult(new Exception("Prospect not found"));
if (entityProspect == null) return new(new Exception("Prospect not found"));
entityProspect.Memo = prospect.Memo;
entityProspect.Name = prospect.Name;
@@ -175,14 +175,14 @@ namespace FoodsharingSiegen.Server.Data.Service
var saveR = await Context.SaveChangesAsync();
if(saveR < 1) return new OperationResult(new Exception("Fehler beim speichern"));
if(saveR < 1) return new(new Exception("Fehler beim speichern"));
await AuditService.Insert(AuditType.EditProspect, prospect.Name);
return new OperationResult();
return new();
}
catch (Exception e)
{
return new OperationResult(e);
return new(e);
}
}