-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMutation.cs
More file actions
58 lines (52 loc) · 1.85 KB
/
Copy pathMutation.cs
File metadata and controls
58 lines (52 loc) · 1.85 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System.Linq;
using GraphQLAdaptor.Models;
namespace GraphQLAdaptor.GraphQL
{
public class OrdersDetailsInput
{
[GraphQLName("OrderID")]
public int? OrderID { get; set; }
[GraphQLName("CustomerID")]
public string? CustomerID { get; set; }
[GraphQLName("EmployeeID")]
public int? EmployeeID { get; set; }
[GraphQLName("Freight")]
public double? Freight { get; set; }
}
public class Mutation
{
public OrdersDetails AddOrder(OrdersDetailsInput input)
{
var newOrder = new OrdersDetails
{
OrderID = input.OrderID,
CustomerID = input.CustomerID,
EmployeeID = input.EmployeeID,
Freight = input.Freight
};
OrdersDetails.GetAllRecords().Insert(0, newOrder);
return newOrder;
}
public OrdersDetails? UpdateOrder(int key, string? keyColumn, OrdersDetailsInput input)
{
// Find the order by the key (OrderID)
var existing = OrdersDetails.GetAllRecords().FirstOrDefault(o => o.OrderID == key);
if (existing == null) return null;
// Update only the fields that are provided
if (input.CustomerID != null)
existing.CustomerID = input.CustomerID;
if (input.EmployeeID.HasValue)
existing.EmployeeID = input.EmployeeID;
if (input.Freight != null)
existing.Freight = input.Freight;
return existing;
}
public bool DeleteOrder(int orderID)
{
var existing = OrdersDetails.GetAllRecords().FirstOrDefault(o => o.OrderID == orderID);
if (existing == null) return false;
OrdersDetails.GetAllRecords().Remove(existing);
return true;
}
}
}