Add edit functionality for EinAb interactions: implement UpdateInteraction method, extend InteractionDialog for edit mode, and add edit button in InteractionRow
This commit is contained in:
@@ -174,6 +174,53 @@ namespace FoodsharingSiegen.Server.Data.Service
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method UpdateInteraction
|
||||
|
||||
/// <summary>
|
||||
/// Updates an existing interaction with the specified values.
|
||||
/// </summary>
|
||||
/// <param name="interaction">The interaction with updated values.</param>
|
||||
/// <returns>A task containing an operation result of interaction.</returns>
|
||||
public async Task<OperationResult<Interaction>> UpdateInteraction(Interaction interaction)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entityInteraction = await Context.Interactions!.FirstOrDefaultAsync(x => x.Id == interaction.Id);
|
||||
if (entityInteraction == null) return new(new Exception("Interaction not found"));
|
||||
|
||||
entityInteraction.Date = interaction.Date;
|
||||
entityInteraction.Info1 = interaction.Info1;
|
||||
entityInteraction.Info2 = interaction.Info2;
|
||||
entityInteraction.Feedback = interaction.Feedback;
|
||||
entityInteraction.FeedbackInfo = interaction.FeedbackInfo;
|
||||
entityInteraction.Alert = interaction.Alert;
|
||||
|
||||
var prospect = await Context.Prospects!.FirstOrDefaultAsync(x => x.Id == entityInteraction.ProspectID);
|
||||
if (prospect != null)
|
||||
{
|
||||
prospect.Modified = DateTime.UtcNow;
|
||||
}
|
||||
|
||||
await Context.SaveChangesAsync();
|
||||
|
||||
if (prospect != null)
|
||||
{
|
||||
await AuditService.Insert(AuditType.EditInteraction, prospect.Name, entityInteraction.Type.ToString());
|
||||
}
|
||||
|
||||
Context.Entry(entityInteraction).State = EntityState.Detached;
|
||||
if (prospect != null) Context.Entry(prospect).State = EntityState.Detached;
|
||||
|
||||
return new(entityInteraction);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new(e);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Method UpdateAsync
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user