-
Notifications
You must be signed in to change notification settings - Fork 0
/
PizzaDb.cs
50 lines (47 loc) · 1.37 KB
/
PizzaDb.cs
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
namespace PizzaStore
{
public record Pizza
{
public int? Id { get; set; }
public string? Name { get; set; }
}
public class PizzaDb
{
private static List<Pizza> _pizzas = new List<Pizza>()
{
new Pizza{ Id=1, Name="Montemagno, Pizza shaped like a great mountain" },
new Pizza{ Id=2, Name="The Galloway, Pizza shaped like a submarine, silent but deadly"},
new Pizza{ Id=3, Name="The Noring, Pizza shaped like a Viking helmet, where's the mead"}
};
public static List<Pizza> GetPizzas()
{
return _pizzas;
}
public static Pizza? GetPizza(int id)
{
return _pizzas.SingleOrDefault(pizza => pizza.Id == id);
}
public static Pizza CreatePizza(Pizza pizza)
{
_pizzas.Add(pizza);
return pizza;
}
public static Pizza UpdatePizza(Pizza update)
{
_pizzas = _pizzas.Select(pizza =>
{
if (pizza.Id == update.Id)
{
pizza.Name = update.Name;
}
return pizza;
}).ToList();
return update;
}
//Well structured idea
public static void RemovePizza(int id)
{
_pizzas = _pizzas.FindAll(pizza => pizza.Id != id).ToList();
}
}
}