ProspectService updates
This commit is contained in:
@@ -33,16 +33,17 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
{
|
||||
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"));
|
||||
|
||||
var dummyUser = Context.Users.First().Id;
|
||||
|
||||
interaction.ProspectId = Guid.Empty;
|
||||
interaction.UserId = dummyUser;
|
||||
|
||||
targetProspect.Interactions.Add(interaction);
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
// Detatch entities
|
||||
Context.Entry(targetProspect).State = EntityState.Detached;
|
||||
Context.Entry(interaction).State = EntityState.Detached;
|
||||
|
||||
return new OperationResult<Interaction>(interaction);
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -53,6 +54,21 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<OperationResult> RemoveInteraction(Guid interactionId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Context.Interactions.Remove(new Interaction { Id = interactionId });
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
return new OperationResult();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new OperationResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
#region Public Method AddProspectAsync
|
||||
|
||||
/// <summary>
|
||||
@@ -95,7 +111,7 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
{
|
||||
try
|
||||
{
|
||||
var prospects = await Context.Prospects.Include(x => x.Interactions).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync();
|
||||
var prospects = await Context.Prospects.AsNoTracking().Include(x => x.Interactions).ThenInclude(x => x.User).OrderBy(x => x.Name).ToListAsync();
|
||||
return new OperationResult<List<Prospect>>(prospects);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
Reference in New Issue
Block a user