Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,4 @@ $RECYCLE.BIN/
*/**/obj/Release
/exercise.pizzashopapi/appsettings.json
/exercise.pizzashopapi/appsettings.Development.json
*/Migrations
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/Request/CustomerPost - Copy.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class CustomerPut
{
public string? Name { get; set; }
}
}
9 changes: 9 additions & 0 deletions exercise.pizzashopapi/DTO/Request/CustomerPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class CustomerPost
{
public string Name { get; set; }
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Request/OrderPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class OrderPost
{
public int CustomerId { get; set; }
public int PizzaId { get; set; }
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Request/OrderPut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class OrderPut
{
public int? CustomerId { get; set; }
public int? PizzaId { get; set; }
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Request/PizzaPost.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class PizzaPost
{
public string Name { get; set; }
public decimal Price { get; set; }
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Request/PizzaPut.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class PizzaPut
{
public string? Name { get; set; }
public decimal? Price { get; set; }
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Response/CustomerDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class CustomerDTO
{
public int Id { get; set; }
public string Name { get; set; }
public List<OrderCustomerDTO> Orders { get; set;} = new List<OrderCustomerDTO>();
}
}
11 changes: 11 additions & 0 deletions exercise.pizzashopapi/DTO/Response/OrderCustomerDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class OrderCustomerDTO
{
public string PizzaName { get; set; }
public decimal PizzaPrice { get; set; }
}
}
13 changes: 13 additions & 0 deletions exercise.pizzashopapi/DTO/Response/OrderDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class OrderDTO
{
public int Id { get; set; }
public string CustomerName { get; set; }
public string PizzaName { get; set; }
public decimal PizzaPrice { get; set; }
}
}
12 changes: 12 additions & 0 deletions exercise.pizzashopapi/DTO/Response/PizzaDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace exercise.pizzashopapi.Models
{
public class PizzaDTO
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
}
8 changes: 1 addition & 7 deletions exercise.pizzashopapi/Data/DataContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@ public class DataContext : DbContext
public DataContext()
{
var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString");

connectionString = configuration.GetValue<string>("ConnectionStrings:DefaultConnectionString")!;
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseNpgsql(connectionString);

//set primary of order?

//seed data?

}
public DbSet<Pizza> Pizzas { get; set; }
public DbSet<Customer> Customers { get; set; }
Expand Down
24 changes: 20 additions & 4 deletions exercise.pizzashopapi/Data/Seeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,36 @@ public async static void SeedPizzaShopApi(this WebApplication app)
{
db.Add(new Customer() { Name="Nigel" });
db.Add(new Customer() { Name = "Dave" });
db.Add(new Customer() { Name = "Tonnes" });
await db.SaveChangesAsync();
}
if(!db.Pizzas.Any())
{
db.Add(new Pizza() { Name = "Cheese & Pineapple" });
db.Add(new Pizza() { Name = "Vegan Cheese Tastic" });
db.Add(new Pizza() { Name = "Cheese & Pineapple", Price = 140});
db.Add(new Pizza() { Name = "Vegan Cheese Tastic", Price = 130});
db.Add(new Pizza() { Name = "Pepperoni & Pineapple", Price = 150});
await db.SaveChangesAsync();

}

//order data
if(1==1)
if(!db.Orders.Any())
{

db.Add(new Order
{
CustomerId = 1,
PizzaId = 1,
});
db.Add(new Order
{
CustomerId = 2,
PizzaId = 2,
});
db.Add(new Order
{
CustomerId = 2,
PizzaId = 2,
});
await db.SaveChangesAsync();
}
}
Expand Down
Loading