merge: bring in feature-add-shared-base-entity
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
commit 85cbab22a8d58acf53e32bc122329b50170de1a0 Author: surtur <a_mirre@utb.cz> Date: Wed Dec 30 00:53:27 2020 +0100 chore: update proj file to include Migrations dir commit 71bcd9fa486b761b83ad488d51e9fde5b5d8565f Author: surtur <a_mirre@utb.cz> Date: Tue Dec 29 23:28:17 2020 +0100 chore: prevent deletion of products used in orders commit d9ddee09d78c8e50dbf4f5bcbe07b80294de62e8 Author: surtur <a_mirre@utb.cz> Date: Tue Dec 29 19:45:40 2020 +0100 chore: add db conf for {Product,Carousel,Order} * csproj pkg cleanup commit 66c9c1cb520373b91723e2f4ef8d4bc76e05d8a9 Author: surtur <a_mirre@utb.cz> Date: Tue Dec 29 17:48:09 2020 +0100 chore: create a shared base entity
This commit is contained in:
parent
37cfb08acb
commit
421a8f5f62
|
@ -5,11 +5,8 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
namespace pwt_0x01_ng.Models
|
||||
{
|
||||
[Table("Carousel")]
|
||||
public class Carousel
|
||||
public class Carousel : Entity
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public int id { get; set; }
|
||||
[Required]
|
||||
public string DataTarget { get; set; }
|
||||
[NotMapped]
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace pwt_0x01_ng.Models.Database.Conf
|
||||
{
|
||||
public class CarouselConf : IEntityTypeConfiguration<Carousel>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Carousel> builder)
|
||||
{
|
||||
builder.Property(nameof(Carousel.Created)).ValueGeneratedOnAdd().HasDefaultValueSql("NOW()");
|
||||
builder.Property(nameof(Carousel.Updated)).ValueGeneratedOnUpdate().HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
// using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace pwt_0x01_ng.Models.Database.Conf
|
||||
{
|
||||
public class OrderConf : IEntityTypeConfiguration<Order>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Order> builder)
|
||||
{
|
||||
builder.HasMany(order => order.OrderItems).WithOne(item => item.Order).IsRequired().HasForeignKey(item => item.Order_id).OnDelete(DeleteBehavior.Restrict);
|
||||
builder.Property(nameof(Order.Created)).ValueGeneratedOnAdd().HasDefaultValueSql("NOW()");
|
||||
builder.Property(nameof(Order.Updated)).ValueGeneratedOnUpdate().HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace pwt_0x01_ng.Models.Database.Conf
|
||||
{
|
||||
public class OrderItemConf : IEntityTypeConfiguration<OrderItem>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrderItem> builder)
|
||||
{
|
||||
builder.Property(nameof(OrderItem.Created)).ValueGeneratedOnAdd().HasDefaultValueSql("NOW()");
|
||||
builder.Property(nameof(OrderItem.Updated)).ValueGeneratedOnUpdate().HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace pwt_0x01_ng.Models.Database.Conf
|
||||
{
|
||||
public class ProductConf : IEntityTypeConfiguration<Product>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Product> builder)
|
||||
{
|
||||
builder.Property(nameof(Product.Created)).ValueGeneratedOnAdd().HasDefaultValueSql("NOW()");
|
||||
builder.Property(nameof(Product.Updated)).ValueGeneratedOnUpdate().HasDefaultValueSql("NOW()");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Npgsql.EntityFrameworkCore;
|
||||
using pwt_0x01_ng.Models;
|
||||
using pwt_0x01_ng.Models.Database.Conf;
|
||||
|
||||
namespace pwt_0x01_ng.Models.Database
|
||||
{
|
||||
|
@ -14,5 +16,21 @@ namespace pwt_0x01_ng.Models.Database
|
|||
|
||||
public DbSet<Carousel> Carousel { get; set; }
|
||||
public DbSet<Product> Product { get; set; }
|
||||
public DbSet<Order> Order { get; set; }
|
||||
public DbSet<OrderItem> OrderItem { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder model_builder)
|
||||
{
|
||||
base.OnModelCreating(model_builder);
|
||||
this.ApplyConfiguration(model_builder);
|
||||
}
|
||||
|
||||
protected virtual void ApplyConfiguration(ModelBuilder model_builder)
|
||||
{
|
||||
model_builder.ApplyConfiguration(new CarouselConf());
|
||||
model_builder.ApplyConfiguration(new ProductConf());
|
||||
model_builder.ApplyConfiguration(new OrderConf());
|
||||
model_builder.ApplyConfiguration(new OrderItemConf());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace pwt_0x01_ng.Models.Database
|
|||
{
|
||||
dbContext.Carousel.Add(c);
|
||||
}
|
||||
dbContext.SaveChanges();
|
||||
|
||||
IList<Product> products = ProductHelper.GenerateProduct();
|
||||
foreach (var p in products)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
//using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace pwt_0x01_ng.Models
|
||||
{
|
||||
public abstract class Entity
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public int id { get; set; }
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public DateTime Created { get; protected set; }
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Computed)]
|
||||
public DateTime Updated { get; protected set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace pwt_0x01_ng.Models
|
||||
{
|
||||
[Table(nameof(Order))]
|
||||
public class Order : Entity
|
||||
{
|
||||
[Required]
|
||||
public string Order_Number { get; set; }
|
||||
[Required]
|
||||
public IList<OrderItem> OrderItems { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
//using Microsoft.AspNetCore.Http;
|
||||
|
||||
namespace pwt_0x01_ng.Models
|
||||
{
|
||||
[Table(nameof(OrderItem))]
|
||||
public class OrderItem : Entity
|
||||
{
|
||||
[ForeignKey(nameof(Order))]
|
||||
[Required]
|
||||
public int Order_id { get; set; }
|
||||
[ForeignKey(nameof(Product))]
|
||||
[Required]
|
||||
public int Product_id { get; set; }
|
||||
[Required]
|
||||
public int Amount { get; set; }
|
||||
[Required]
|
||||
public decimal Price { get; set; }
|
||||
public Order Order { get; set; }
|
||||
public Product Product {get; set; }
|
||||
}
|
||||
}
|
|
@ -5,11 +5,8 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
namespace pwt_0x01_ng.Models
|
||||
{
|
||||
[Table("Product")]
|
||||
public class Product
|
||||
public class Product : Entity
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public int id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
[Required]
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="3.1.4" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.10" />
|
||||
</ItemGroup>
|
||||
|
@ -21,7 +22,9 @@
|
|||
<ItemGroup>
|
||||
<Folder Include="Areas\Admin\Data" />
|
||||
<Folder Include="Areas\Admin\Models" />
|
||||
<Folder Include="Migrations\pgsql" />
|
||||
<Folder Include="Models\Database" />
|
||||
<Folder Include="Models\Database\Conf" />
|
||||
<Folder Include="wwwroot\images\carousels" />
|
||||
<Folder Include="wwwroot\images\products" />
|
||||
</ItemGroup>
|
||||
|
|
Reference in New Issue