-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSaveExplicitSamples.cs
More file actions
38 lines (32 loc) · 1.25 KB
/
SaveExplicitSamples.cs
File metadata and controls
38 lines (32 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using EmployeeManagement.Domain.Samples.SaveOperation;
using Neatoo.RemoteFactory;
namespace EmployeeManagement.Application.Samples.SaveOperation;
// ============================================================================
// Save vs Explicit Method Calls
// ============================================================================
/// <summary>
/// Demonstrates Save method vs explicit Insert/Update/Delete calls.
/// </summary>
public class SaveVsExplicitDemo
{
private readonly IEmployeeCrudFactory _factory;
public SaveVsExplicitDemo(IEmployeeCrudFactory factory)
{
_factory = factory;
}
public async Task UsingSaveAsync()
{
var employee = _factory.Create();
employee.FirstName = "John";
employee.LastName = "Doe";
employee.DepartmentId = Guid.NewGuid();
#region save-explicit
// Save: state-based routing (single "Save" button in UI)
await _factory.Save(employee); // Routes to Insert (IsNew=true)
employee.FirstName = "Jane";
await _factory.Save(employee); // Routes to Update (IsNew=false)
employee.IsDeleted = true;
await _factory.Save(employee); // Routes to Delete (IsDeleted=true)
#endregion
}
}