diff --git a/Desktop/Supermarket/Supermarket/App.xaml b/Desktop/Supermarket/Supermarket/App.xaml index 71333e8..b277347 100644 --- a/Desktop/Supermarket/Supermarket/App.xaml +++ b/Desktop/Supermarket/Supermarket/App.xaml @@ -1,9 +1,24 @@  - + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.Designer.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.Designer.cs new file mode 100644 index 0000000..e0aaa11 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.Designer.cs @@ -0,0 +1,350 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Supermarket.Data; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + [DbContext(typeof(SupermarketDbContext))] + [Migration("20240610115741_ProductCategory")] + partial class ProductCategory + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AddresLine1") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AddresLine2") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("CustomerAddres"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Total") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("OrderDetailsId") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderDetailsId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("InventoryId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("InventoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ProductCategories"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductInventory"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("CustomerAddresses") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("OrderDetails") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.HasOne("Supermarket.Models.OrderDetails", "OrderDetails") + .WithMany("OrderItems") + .HasForeignKey("OrderDetailsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.Product", "Product") + .WithMany("OrderItems") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderDetails"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.HasOne("Supermarket.Models.ProductCategory", "Category") + .WithMany("Products") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.ProductInventory", "Inventory") + .WithMany("Products") + .HasForeignKey("InventoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Inventory"); + }); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Navigation("CustomerAddresses"); + + b.Navigation("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.cs new file mode 100644 index 0000000..6fe1ed1 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610115741_ProductCategory.cs @@ -0,0 +1,229 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + /// + public partial class ProductCategory : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "Customers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + FirstName = table.Column(type: "nvarchar(max)", nullable: false), + LastName = table.Column(type: "nvarchar(max)", nullable: false), + Telephone = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + UserName = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Customers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProductCategories", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + DeletedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductCategories", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "ProductInventory", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Quantity = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + DeletedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductInventory", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "CustomerAddres", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CustomerId = table.Column(type: "int", nullable: false), + AddresLine1 = table.Column(type: "nvarchar(max)", nullable: false), + AddresLine2 = table.Column(type: "nvarchar(max)", nullable: false), + Country = table.Column(type: "nvarchar(max)", nullable: false), + City = table.Column(type: "nvarchar(max)", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CustomerAddres", x => x.Id); + table.ForeignKey( + name: "FK_CustomerAddres_Customers_CustomerId", + column: x => x.CustomerId, + principalTable: "Customers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderDetails", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + CustomerId = table.Column(type: "int", nullable: false), + Total = table.Column(type: "decimal(18,2)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderDetails", x => x.Id); + table.ForeignKey( + name: "FK_OrderDetails_Customers_CustomerId", + column: x => x.CustomerId, + principalTable: "Customers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "Products", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + Name = table.Column(type: "nvarchar(max)", nullable: false), + Description = table.Column(type: "nvarchar(max)", nullable: false), + CategoryId = table.Column(type: "int", nullable: false), + InventoryId = table.Column(type: "int", nullable: false), + Price = table.Column(type: "decimal(18,2)", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + DeletedAt = table.Column(type: "datetime2", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Products", x => x.Id); + table.ForeignKey( + name: "FK_Products_ProductCategories_CategoryId", + column: x => x.CategoryId, + principalTable: "ProductCategories", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Products_ProductInventory_InventoryId", + column: x => x.InventoryId, + principalTable: "ProductInventory", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "OrderItems", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + OrderId = table.Column(type: "int", nullable: false), + ProductId = table.Column(type: "int", nullable: false), + Quantity = table.Column(type: "int", nullable: false), + CreatedAt = table.Column(type: "datetime2", nullable: false), + ModifiedAt = table.Column(type: "datetime2", nullable: false), + OrderDetailsId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_OrderItems", x => x.Id); + table.ForeignKey( + name: "FK_OrderItems_OrderDetails_OrderDetailsId", + column: x => x.OrderDetailsId, + principalTable: "OrderDetails", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_OrderItems_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_CustomerAddres_CustomerId", + table: "CustomerAddres", + column: "CustomerId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderDetails_CustomerId", + table: "OrderDetails", + column: "CustomerId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_OrderDetailsId", + table: "OrderItems", + column: "OrderDetailsId"); + + migrationBuilder.CreateIndex( + name: "IX_OrderItems_ProductId", + table: "OrderItems", + column: "ProductId"); + + migrationBuilder.CreateIndex( + name: "IX_Products_CategoryId", + table: "Products", + column: "CategoryId"); + + migrationBuilder.CreateIndex( + name: "IX_Products_InventoryId", + table: "Products", + column: "InventoryId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CustomerAddres"); + + migrationBuilder.DropTable( + name: "OrderItems"); + + migrationBuilder.DropTable( + name: "OrderDetails"); + + migrationBuilder.DropTable( + name: "Products"); + + migrationBuilder.DropTable( + name: "Customers"); + + migrationBuilder.DropTable( + name: "ProductCategories"); + + migrationBuilder.DropTable( + name: "ProductInventory"); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.Designer.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.Designer.cs new file mode 100644 index 0000000..0fac633 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.Designer.cs @@ -0,0 +1,350 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Supermarket.Data; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + [DbContext(typeof(SupermarketDbContext))] + [Migration("20240610120459_ProductInventory")] + partial class ProductInventory + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AddresLine1") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AddresLine2") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("CustomerAddres"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Total") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("OrderDetailsId") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderDetailsId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("InventoryId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("InventoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ProductCategories"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductInventory"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("CustomerAddresses") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("OrderDetails") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.HasOne("Supermarket.Models.OrderDetails", "OrderDetails") + .WithMany("OrderItems") + .HasForeignKey("OrderDetailsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.Product", "Product") + .WithMany("OrderItems") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderDetails"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.HasOne("Supermarket.Models.ProductCategory", "Category") + .WithMany("Products") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.ProductInventory", "Inventory") + .WithMany("Products") + .HasForeignKey("InventoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Inventory"); + }); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Navigation("CustomerAddresses"); + + b.Navigation("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.cs new file mode 100644 index 0000000..4cb7427 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120459_ProductInventory.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + /// + public partial class ProductInventory : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.Designer.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.Designer.cs new file mode 100644 index 0000000..ee84cd1 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.Designer.cs @@ -0,0 +1,350 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Supermarket.Data; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + [DbContext(typeof(SupermarketDbContext))] + [Migration("20240610120531_Product")] + partial class Product + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AddresLine1") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AddresLine2") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("CustomerAddres"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Total") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("OrderDetailsId") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderDetailsId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("InventoryId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("InventoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ProductCategories"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductInventory"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("CustomerAddresses") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("OrderDetails") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.HasOne("Supermarket.Models.OrderDetails", "OrderDetails") + .WithMany("OrderItems") + .HasForeignKey("OrderDetailsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.Product", "Product") + .WithMany("OrderItems") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderDetails"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.HasOne("Supermarket.Models.ProductCategory", "Category") + .WithMany("Products") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.ProductInventory", "Inventory") + .WithMany("Products") + .HasForeignKey("InventoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Inventory"); + }); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Navigation("CustomerAddresses"); + + b.Navigation("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.cs new file mode 100644 index 0000000..027969e --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/20240610120531_Product.cs @@ -0,0 +1,22 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + /// + public partial class Product : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/Migrations/SupermarketDbContextModelSnapshot.cs b/Desktop/Supermarket/Supermarket/Data/Migrations/SupermarketDbContextModelSnapshot.cs new file mode 100644 index 0000000..f9c2167 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/Migrations/SupermarketDbContextModelSnapshot.cs @@ -0,0 +1,347 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Supermarket.Data; + +#nullable disable + +namespace Supermarket.Data.Migrations +{ + [DbContext(typeof(SupermarketDbContext))] + partial class SupermarketDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.6") + .HasAnnotation("Relational:MaxIdentifierLength", 128); + + SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("Customers"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("AddresLine1") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("AddresLine2") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("City") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Country") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("CustomerAddres"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("CustomerId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Total") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CustomerId"); + + b.ToTable("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("OrderDetailsId") + .HasColumnType("int"); + + b.Property("OrderId") + .HasColumnType("int"); + + b.Property("ProductId") + .HasColumnType("int"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("OrderDetailsId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CategoryId") + .HasColumnType("int"); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("InventoryId") + .HasColumnType("int"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Price") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("CategoryId"); + + b.HasIndex("InventoryId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("Description") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Name") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.ToTable("ProductCategories"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("CreatedAt") + .HasColumnType("datetime2"); + + b.Property("DeletedAt") + .HasColumnType("datetime2"); + + b.Property("ModifiedAt") + .HasColumnType("datetime2"); + + b.Property("Quantity") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("ProductInventory"); + }); + + modelBuilder.Entity("Supermarket.Models.CustomerAddres", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("CustomerAddresses") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.HasOne("Supermarket.Models.Customer", "Customer") + .WithMany("OrderDetails") + .HasForeignKey("CustomerId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Customer"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderItems", b => + { + b.HasOne("Supermarket.Models.OrderDetails", "OrderDetails") + .WithMany("OrderItems") + .HasForeignKey("OrderDetailsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.Product", "Product") + .WithMany("OrderItems") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("OrderDetails"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.HasOne("Supermarket.Models.ProductCategory", "Category") + .WithMany("Products") + .HasForeignKey("CategoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Supermarket.Models.ProductInventory", "Inventory") + .WithMany("Products") + .HasForeignKey("InventoryId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Category"); + + b.Navigation("Inventory"); + }); + + modelBuilder.Entity("Supermarket.Models.Customer", b => + { + b.Navigation("CustomerAddresses"); + + b.Navigation("OrderDetails"); + }); + + modelBuilder.Entity("Supermarket.Models.OrderDetails", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.Product", b => + { + b.Navigation("OrderItems"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductCategory", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("Supermarket.Models.ProductInventory", b => + { + b.Navigation("Products"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Data/SupermarketDbContext.cs b/Desktop/Supermarket/Supermarket/Data/SupermarketDbContext.cs new file mode 100644 index 0000000..8342481 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Data/SupermarketDbContext.cs @@ -0,0 +1,26 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Models; +namespace Supermarket.Data +{ + internal class SupermarketDbContext : DbContext + { + public virtual DbSet ProductCategories { get; set; } + public virtual DbSet ProductInventory { get; set; } + public virtual DbSetProducts { get; set; } + public virtual DbSet Customers { get; set; } + public virtual DbSet CustomerAddres { get; set; } + public virtual DbSet OrderDetails { get; set; } + public virtual DbSet OrderItems { get; set; } + + public SupermarketDbContext() + { + + } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + optionsBuilder.UseSqlServer(@"Data Source=HP-PC\SQLEXPRESS;Initial Catalog=SupermarketManagementOtabek;Integrated Security=True;Pooling=False;Encrypt=True;Trust Server Certificate=True"); + base.OnConfiguring(optionsBuilder); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/MainWindow.xaml b/Desktop/Supermarket/Supermarket/MainWindow.xaml index e1b2f67..c2cefaa 100644 --- a/Desktop/Supermarket/Supermarket/MainWindow.xaml +++ b/Desktop/Supermarket/Supermarket/MainWindow.xaml @@ -1,12 +1,308 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/MainWindow.xaml.cs b/Desktop/Supermarket/Supermarket/MainWindow.xaml.cs index 720a159..fc5f598 100644 --- a/Desktop/Supermarket/Supermarket/MainWindow.xaml.cs +++ b/Desktop/Supermarket/Supermarket/MainWindow.xaml.cs @@ -1,13 +1,5 @@ -using System.Text; +using Supermarket.View; using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; namespace Supermarket { @@ -20,5 +12,43 @@ public MainWindow() { InitializeComponent(); } + + private void CategoryView(object sender, RoutedEventArgs e) + { + ProductCatigories userControl = new ProductCatigories(); + + Window parentWindow = Window.GetWindow(userControl); + MainContentControl.Content = userControl; + } + private void InventoryView(object sender, RoutedEventArgs e) + { + Supermarket.View.ProductInventories userControl = new View.ProductInventories(); + Window parentWindow = Window.GetWindow(userControl); + MainContentControl.Content = userControl; + } + private void ProductsView(object sender, RoutedEventArgs e) + { + Products userControl = new Products(); + Window parentWindow = Window.GetWindow(userControl); + MainContentControl.Content = userControl; + } + private void HomeView(object sender, RoutedEventArgs e) + { + MainWindow window = new MainWindow(); + window.Show(); + } + private void CustomerView(object sender, RoutedEventArgs e) + { + Customers userControl = new Customers(); + Window parentWindow = Window.GetWindow(userControl); + MainContentControl.Content = userControl; + } + private void OrdersView(object sender, RoutedEventArgs e) + { + Orders userControl = new Orders(); + Window parentWindow = Window.GetWindow(userControl); + MainContentControl.Content = userControl; + } + } } \ No newline at end of file diff --git a/Desktop/Supermarket/Supermarket/Models/Customer.cs b/Desktop/Supermarket/Supermarket/Models/Customer.cs new file mode 100644 index 0000000..212e453 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/Customer.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Models +{ + public class Customer + { + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Telephone { get; set; } + public string Password { get; set; } + public string UserName { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public ICollection OrderDetails { get; set; } + public ICollection CustomerAddresses { get; set; } + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/CustomerAddres.cs b/Desktop/Supermarket/Supermarket/Models/CustomerAddres.cs new file mode 100644 index 0000000..0cec191 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/CustomerAddres.cs @@ -0,0 +1,15 @@ +namespace Supermarket.Models +{ + public class CustomerAddres + { + public int Id { get; set; } + public int CustomerId { get; set; } + public string AddresLine1 { get; set; } + public string AddresLine2 { get; set; } + public string Country { get; set; } + public string City { get; set; } + + public Customer Customer { get; set; } + + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/OrderDetails.cs b/Desktop/Supermarket/Supermarket/Models/OrderDetails.cs new file mode 100644 index 0000000..c3695b7 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/OrderDetails.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Models +{ + public class OrderDetails + { + public int Id { get; set; } + public int CustomerId { get; set; } + public decimal Total { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set;} + public Customer Customer { get; set; } + public ICollection OrderItems { get; set; } + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/OrderItems.cs b/Desktop/Supermarket/Supermarket/Models/OrderItems.cs new file mode 100644 index 0000000..08e310a --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/OrderItems.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Models +{ + public class OrderItems + { + public int Id { get; set; } + public int OrderId { get; set; } + public int ProductId { get; set; } + public int Quantity { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set;} + public OrderDetails OrderDetails { get; set; } + public Product Product { get; set; } + + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/Product.cs b/Desktop/Supermarket/Supermarket/Models/Product.cs new file mode 100644 index 0000000..9bba32d --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/Product.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Models +{ + public class Product + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public int CategoryId { get; set; } + public int InventoryId { get; set; } + public decimal Price { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public DateTime DeletedAt { get; set; } + public ProductCategory Category { get; set; } + public ProductInventory Inventory { get; set; } + public ICollection OrderItems { get; set; } + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/ProductCategory.cs b/Desktop/Supermarket/Supermarket/Models/ProductCategory.cs new file mode 100644 index 0000000..5bb338e --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/ProductCategory.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Models +{ + public class ProductCategory + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public DateTime DeletedAt { get; set; } + public ICollection Products { get; set; } + } +} diff --git a/Desktop/Supermarket/Supermarket/Models/ProductInventory.cs b/Desktop/Supermarket/Supermarket/Models/ProductInventory.cs new file mode 100644 index 0000000..2d7ba58 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Models/ProductInventory.cs @@ -0,0 +1,12 @@ +namespace Supermarket.Models +{ + public class ProductInventory + { + public int Id { get; set; } + public int Quantity { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public DateTime DeletedAt { get; set; } + public ICollection Products { get; set; } + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/CategoryService.cs b/Desktop/Supermarket/Supermarket/Service/CategoryService.cs new file mode 100644 index 0000000..41efe7f --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/CategoryService.cs @@ -0,0 +1,49 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using Supermarket.Models; +using System.Collections.Generic; + +namespace Supermarket.Service +{ + + public class CategoryService + { + private readonly SupermarketDbContext _context; + + public CategoryService() + { + _context = new SupermarketDbContext(); + } + + public List GetProductCategories(string search = "") + { + var query = _context.ProductCategories + .AsNoTracking(); + // Optional: AsNoTracking() for read-only operations; + if (!string.IsNullOrEmpty(search)) + { + query = query.Where(x => x.Name.Contains(search) || + x.Description.Contains(search)); + } + return query.ToList(); + } + + public void Create(ProductCategory category) + { + _context.ProductCategories.Add(category); + _context.SaveChanges(); + } + + public void Update(ProductCategory category) + { + _context.ProductCategories.Update(category); + _context.SaveChanges(); + } + + public void Delete(ProductCategory category) + { + _context.ProductCategories.Remove(category); + _context.SaveChanges(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/CustomerAddressService.cs b/Desktop/Supermarket/Supermarket/Service/CustomerAddressService.cs new file mode 100644 index 0000000..230bc95 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/CustomerAddressService.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using Supermarket.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Service +{ + public class CustomerAddressService + { + private readonly SupermarketDbContext _context; + + public CustomerAddressService() + { + _context = new SupermarketDbContext(); + } + public List GetAddress(int id) + { + var query=_context.CustomerAddres + .Where(c => c.Id == id); + return query.ToList(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/CustomerService.cs b/Desktop/Supermarket/Supermarket/Service/CustomerService.cs new file mode 100644 index 0000000..6113be9 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/CustomerService.cs @@ -0,0 +1,38 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Service +{ + public class CustomerService + { + + private readonly SupermarketDbContext _context; + + public CustomerService() + { + _context = new SupermarketDbContext(); + } + public List GetCustomers(string search = "") + { + var query = _context.Customers + .Include(x=>x.OrderDetails) + .ThenInclude(x=>x.OrderItems) + .Include(x=>x.CustomerAddresses) + .AsNoTracking() + .AsQueryable(); + // Optional: AsNoTracking() for read-only operations; + if (!string.IsNullOrEmpty(search)) + { + query = query.Where(x => x.FirstName.Contains(search) || + x.LastName.Contains(search)); + } + return query.ToList(); + } + + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/InventoryService.cs b/Desktop/Supermarket/Supermarket/Service/InventoryService.cs new file mode 100644 index 0000000..e24e8b1 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/InventoryService.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using Supermarket.Models; + +namespace Supermarket.Service +{ + public class InventoryService + { + private readonly SupermarketDbContext _context; + + public InventoryService() + { + _context = new SupermarketDbContext(); + } + public List GetProductInventories(int search = 0) + { + var query = _context.ProductInventory.AsNoTracking(); + + if (search != 0) + { + query = query.Where(x => x.Quantity == search); + } + + return query.ToList(); + } + public void Create(ProductInventory inventory) + { + _context.ProductInventory.Add(inventory); + _context.SaveChanges(); + } + + public void Update(ProductInventory inventory) + { + _context.ProductInventory.Update(inventory); + _context.SaveChanges(); + } + + public void Delete(ProductInventory inventory) + { + _context.ProductInventory.Remove(inventory); + _context.SaveChanges(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/OrderService.cs b/Desktop/Supermarket/Supermarket/Service/OrderService.cs new file mode 100644 index 0000000..0e95988 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/OrderService.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using Supermarket.Models; + +namespace Supermarket.Service +{ + public class OrderService + { + private readonly SupermarketDbContext _context; + + public OrderService() + { + _context = new SupermarketDbContext(); + } + public List GetOrders(int search = 0) + { + var query = _context.OrderDetails + .Include(x => x.OrderItems) + .AsNoTracking() + .AsQueryable(); + if (search != 0) + { + query = query.Where(x => x.Id == search); + } + return query.ToList(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Service/ProductService.cs b/Desktop/Supermarket/Supermarket/Service/ProductService.cs new file mode 100644 index 0000000..aa7bc96 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Service/ProductService.cs @@ -0,0 +1,51 @@ +using Microsoft.EntityFrameworkCore; +using Supermarket.Data; +using Supermarket.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.Service +{ + public class ProductService + { + private readonly SupermarketDbContext _context; + + public ProductService() + { + _context = new SupermarketDbContext(); + } + public List GetProducts(string search = "") + { + var query = _context.Products + .AsNoTracking(); + // Optional: AsNoTracking() for read-only operations; + if (!string.IsNullOrEmpty(search)) + { + query = query.Where(x => x.Name.Contains(search) || + x.Description.Contains(search)); + } + return query.ToList(); + } + + public void Create(Product product) + { + _context.Products.Add(product); + _context.SaveChanges(); + } + + public void Update(Product product) + { + _context.Products.Update(product); + _context.SaveChanges(); + } + + public void Delete(Product product) + { + _context.Products.Remove(product); + _context.SaveChanges(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/Supermarket.csproj b/Desktop/Supermarket/Supermarket/Supermarket.csproj index e3e33e3..8e84dda 100644 --- a/Desktop/Supermarket/Supermarket/Supermarket.csproj +++ b/Desktop/Supermarket/Supermarket/Supermarket.csproj @@ -8,4 +8,15 @@ true + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + diff --git a/Desktop/Supermarket/Supermarket/View/Customers.xaml b/Desktop/Supermarket/Supermarket/View/Customers.xaml new file mode 100644 index 0000000..2144869 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Customers.xaml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/View/Customers.xaml.cs b/Desktop/Supermarket/Supermarket/View/Customers.xaml.cs new file mode 100644 index 0000000..53b7c85 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Customers.xaml.cs @@ -0,0 +1,30 @@ +using Supermarket.ViewModel.Dialogs; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Supermarket.View +{ + /// + /// Interaction logic for Customers.xaml + /// + public partial class Customers : UserControl + { + public Customers() + { + InitializeComponent(); + DataContext = new CustomerViewModel(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/View/Dialogs/AddCategoryDialog.xaml b/Desktop/Supermarket/Supermarket/View/Dialogs/AddCategoryDialog.xaml new file mode 100644 index 0000000..1a8e3a9 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Dialogs/AddCategoryDialog.xaml @@ -0,0 +1,65 @@ + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/View/Orders.xaml.cs b/Desktop/Supermarket/Supermarket/View/Orders.xaml.cs new file mode 100644 index 0000000..8752338 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Orders.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Supermarket.View +{ + /// + /// Interaction logic for Orders.xaml + /// + public partial class Orders : UserControl + { + public Orders() + { + InitializeComponent(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml b/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml new file mode 100644 index 0000000..d4ff536 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml @@ -0,0 +1,112 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml.cs b/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml.cs new file mode 100644 index 0000000..2302429 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/ProductCatigories.xaml.cs @@ -0,0 +1,18 @@ +using Supermarket.ViewModel.Dialogs; +using System.Windows.Controls; + +namespace Supermarket.View +{ + /// + /// Interaction logic for ProductCatigories.xaml + /// + public partial class ProductCatigories : UserControl + { + public ProductCatigories() + { + InitializeComponent(); + DataContext = new ProductCatigoriesViewModel(); + } + + } +} diff --git a/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml b/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml new file mode 100644 index 0000000..648056d --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml @@ -0,0 +1,107 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml.cs b/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml.cs new file mode 100644 index 0000000..52db0ae --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/ProductInventories.xaml.cs @@ -0,0 +1,17 @@ +using Supermarket.ViewModel.Dialogs; +using System.Windows.Controls; + +namespace Supermarket.View +{ + /// + /// Interaction logic for ProductInventories.xaml + /// + public partial class ProductInventories : UserControl + { + public ProductInventories() + { + InitializeComponent(); + DataContext = new ProductInventoriesViewModel(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/View/Products.xaml b/Desktop/Supermarket/Supermarket/View/Products.xaml new file mode 100644 index 0000000..54e00b7 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Products.xaml @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Desktop/Supermarket/Supermarket/View/Products.xaml.cs b/Desktop/Supermarket/Supermarket/View/Products.xaml.cs new file mode 100644 index 0000000..5fb34c7 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/View/Products.xaml.cs @@ -0,0 +1,17 @@ +using Supermarket.ViewModel; +using System.Windows.Controls; + +namespace Supermarket.View +{ + /// + /// Interaction logic for Products.xaml + /// + public partial class Products : UserControl + { + public Products() + { + InitializeComponent(); + DataContext = new ProductsViewModel(); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerDetailsViewModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerDetailsViewModel.cs new file mode 100644 index 0000000..28c89f3 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerDetailsViewModel.cs @@ -0,0 +1,60 @@ +using MvvmHelpers; +using Supermarket.Models; +using Supermarket.Service; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.ViewModel.Dialogs +{ + public class CustomerDetailsViewModel:BaseViewModel + { + CustomerAddressService customerAddressService=new CustomerAddressService(); + private string _historyTitle = string.Empty; + public string HistoryTitle + { + get => _historyTitle; + set => SetProperty(ref _historyTitle, value); + } + private CustomerAddres _selectedAddress; + public CustomerAddres SelectedAddress + { + get => _selectedAddress; + set => SetProperty(ref _selectedAddress, value); + } + public int Id { get; set; } + public string FirstName { get; set; } + public string LastName { get; set; } + public string Telephone { get; set; } + public string Password { get; set; } + public string UserName { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public ObservableCollection Orders { get; } + public ObservableCollection Addresses { get; } + + public CustomerDetailsViewModel(Customer customer ) + { + ArgumentNullException.ThrowIfNull(customer); + Id= customer.Id; + FirstName= customer.FirstName; + LastName= customer.LastName; + Telephone= customer.Telephone; + Password= customer.Password; + UserName= customer.UserName; + CreatedAt=customer.CreatedAt; + ModifiedAt=customer.ModifiedAt; + + Orders = new ObservableCollection(customer.OrderDetails); + HistoryTitle = Orders.Count > 0 + ? "Orders" + : $"{FirstName} {LastName} has no recenet orders"; + Addresses = new ObservableCollection(customerAddressService.GetAddress(customer.Id)); + + } + + } +} diff --git a/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerViewModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerViewModel.cs new file mode 100644 index 0000000..0845ee1 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/CustomerViewModel.cs @@ -0,0 +1,61 @@ +using MvvmHelpers; +using MvvmHelpers.Commands; +using Supermarket.Models; +using Supermarket.Service; +using Supermarket.View; +using Supermarket.View.Dialogs; +using System.Collections.ObjectModel; +using System.Net.Http.Headers; +using System.Windows.Input; + +namespace Supermarket.ViewModel.Dialogs +{ + public class CustomerViewModel : BaseViewModel + { + private readonly CustomerService _customerService; + private ObservableCollection _customers; + public ObservableCollection Customers + { + get => _customers; + set => SetProperty(ref _customers, value); + } + + private Customer _selectedCustomer; + public Customer SelectedCustomer + { + get => _selectedCustomer; + set => SetProperty(ref _selectedCustomer, value); + } + public ICommand ShowDetailsCommand { get; } + public CustomerViewModel() + { + _customerService = new CustomerService(); + Customers = new ObservableCollection(); + ShowDetailsCommand = new Command(OnShowDetails); + LoadCustomers(); + } + private void LoadCustomers() + { + var customers = _customerService.GetCustomers(); + foreach (var customer in customers) + { + Customers.Add(customer); + } + + } + private void OnShowDetails() + { + if (SelectedCustomer is null) + { + return; + } + var dialog = new CustomerDetailsDialog(SelectedCustomer); + dialog.Show(); + } + + + + } +} + + diff --git a/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCategoriesEditModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCategoriesEditModel.cs new file mode 100644 index 0000000..62221e5 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCategoriesEditModel.cs @@ -0,0 +1,33 @@ +using MvvmHelpers; +using Supermarket.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Supermarket.ViewModel.Dialogs +{ + public class ProductCategoriesEditModel:BaseViewModel + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public DateTime CreatedAt { get; set; } + public DateTime ModifiedAt { get; set; } + public DateTime DeletedAt { get; set; } + + public ProductCategoriesEditModel(ProductCategory category) + { + ArgumentNullException.ThrowIfNull(category); + Id = category.Id; + Name = category.Name; + Description = category.Description; + CreatedAt = category.CreatedAt; + ModifiedAt = category.ModifiedAt; + DeletedAt = category.DeletedAt; + + } + + } +} diff --git a/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCatigoriesViewModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCatigoriesViewModel.cs new file mode 100644 index 0000000..cf94add --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductCatigoriesViewModel.cs @@ -0,0 +1,143 @@ +using MvvmHelpers; +using MvvmHelpers.Commands; +using Supermarket.Models; +using Supermarket.Service; +using Supermarket.View.Dialogs; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Windows; +using System.Windows.Input; + +namespace Supermarket.ViewModel.Dialogs +{ + public class ProductCatigoriesViewModel : BaseViewModel + { + private readonly CategoryService _categoryService; + + + public ICommand AddCommand { get; } + public ICommand ShowDetailsCommand { get; } + public ICommand EditCommand { get; } + public ICommand DeleteCommand { get; } + + private ObservableCollection _productCategories; + public ObservableCollection ProductCategories + { + get => _productCategories; + set => SetProperty(ref _productCategories, value); + } + + private ProductCategory _selectedCategory; + public ProductCategory SelectedCategory + { + get => _selectedCategory; + set => SetProperty(ref _selectedCategory, value); + } + + public ProductCatigoriesViewModel() + { + _categoryService = new CategoryService(); + ProductCategories = new ObservableCollection(); + AddCommand = new Command(OnAdd); + ShowDetailsCommand = new Command(OnShowDetails); + EditCommand = new Command(OnEdit); + DeleteCommand = new Command(OnDelete); + LoadCategories(); + } + + private void LoadCategories() + { + var categories = _categoryService.GetProductCategories(); + foreach (var category in categories) + { + ProductCategories.Add(category); + } + } + + private void OnAdd() + { + var dialog = new AddCategoryDialog(); + dialog.ShowDialog(); + } + private void OnShowDetails() + { + + } + + private void OnEdit(ProductCategory category) + { + if (category == null) + { + return; + } + + var dialog = new CatigoryEditDialog(category); + + if (!dialog.ShowDialog() == true) + { + var result = MessageBox.Show( + "Are you sure you want to update?", + "Confirm your action", + MessageBoxButton.YesNo, + MessageBoxImage.Warning); + + if (result == MessageBoxResult.No) + { + return; + } + + try + { + category.ModifiedAt = DateTime.Now; + category.Name=dialog.EditModel.Name; + category.Description=dialog.EditModel.Description; + _categoryService.Update(category); + + // Update the ObservableCollection + var existingCategory = ProductCategories.FirstOrDefault(c => c.Id == category.Id); + if (existingCategory != null) + { + var index = ProductCategories.IndexOf(existingCategory); + ProductCategories[index] = category; + } + + MessageBox.Show( + "Category successfully edited.", + "Success", + MessageBoxButton.OK, + MessageBoxImage.Information); + } + catch (Exception ex) + { + MessageBox.Show( + $"An error occurred while updating the category: {ex.Message}", + "Error", + MessageBoxButton.OK, + MessageBoxImage.Error); + } + } + } + + private void OnDelete(ProductCategory category) + { + var result = MessageBox.Show( + $"Are you sure you want to delete: {category.Name}?", + "Confirm your action.", + MessageBoxButton.YesNo, + MessageBoxImage.Warning); + + if (result == MessageBoxResult.No) + { + return; + } + + _categoryService.Delete(category); + MessageBox.Show( + $"Patient: {category.Name} successfully deleted.", + "Success", + MessageBoxButton.OK, + MessageBoxImage.Information); + } + } +} diff --git a/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductInventoriesViewModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductInventoriesViewModel.cs new file mode 100644 index 0000000..c5b32a4 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/Dialogs/ProductInventoriesViewModel.cs @@ -0,0 +1,102 @@ +using MvvmHelpers; +using MvvmHelpers.Commands; +using Supermarket.Models; +using Supermarket.Service; +using Supermarket.View; +using Supermarket.View.Dialogs; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Input; + +namespace Supermarket.ViewModel.Dialogs +{ + public class ProductInventoriesViewModel:BaseViewModel + { + private readonly InventoryService _inventoryService; + + public ICommand AddCommand { get; } + public ICommand ShowDetailsCommand { get; } + public ICommand EditCommand { get; } + public ICommand DeleteCommand { get; } + + + private ObservableCollection _productInventories; + public ObservableCollection ProductInventories + { + get => _productInventories; + set => SetProperty(ref _productInventories, value); + } + + private ProductInventory _selectedInventory; + public ProductInventory SelectedInventory + { + get => _selectedInventory; + set => SetProperty(ref _selectedInventory, value); + } + + public ProductInventoriesViewModel() + { + _inventoryService = new InventoryService(); + ProductInventories = new ObservableCollection(); + AddCommand = new Command(OnAdd); + ShowDetailsCommand = new Command(OnShowDetails); + EditCommand = new Command(OnEdit); + DeleteCommand = new Command(OnDelete); + LoadInventories(); + } + private void LoadInventories() + { + var inventories = _inventoryService.GetProductInventories(); + foreach(var inventor in inventories) + { + ProductInventories.Add(inventor); + } + } + private void OnAdd() + { + var dialog = new AddInventorydialog(); + dialog.Show(); + } + private void OnShowDetails() + { + + } + private void OnEdit(ProductInventory inventor) + { + + if (inventor == null) + { + return; + } + + + + } + private void OnDelete(ProductInventory inventor) + { + var result = MessageBox.Show( + $"Are you sure you want to delete: {inventor.Quantity}?", + "Confirm your action.", + MessageBoxButton.YesNo, + MessageBoxImage.Warning); + + if (result == MessageBoxResult.No) + { + return; + } + + _inventoryService.Delete(inventor); + MessageBox.Show( + $"Patient: {inventor.Quantity} successfully deleted.", + "Success", + MessageBoxButton.OK, + MessageBoxImage.Information); + + } + } +} diff --git a/Desktop/Supermarket/Supermarket/ViewModel/ProductsViewModel.cs b/Desktop/Supermarket/Supermarket/ViewModel/ProductsViewModel.cs new file mode 100644 index 0000000..8d56dba --- /dev/null +++ b/Desktop/Supermarket/Supermarket/ViewModel/ProductsViewModel.cs @@ -0,0 +1,76 @@ +using MvvmHelpers; +using MvvmHelpers.Commands; +using Supermarket.Models; +using Supermarket.Service; +using Supermarket.View; +using Supermarket.View.Dialogs; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace Supermarket.ViewModel +{ + public class ProductsViewModel:BaseViewModel + { + private readonly ProductService _productService; + + public ICommand AddCommand { get; } + public ICommand ShowDetailsCommand { get; } + public ICommand EditCommand { get; } + public ICommand DeleteCommand { get; } + private ObservableCollection _products; + public ObservableCollection Products + { + get => _products; + set => SetProperty(ref _products, value); + } + + private ProductCategory _selectedProduct; + public ProductCategory SelectedProduct + { + get => _selectedProduct; + set => SetProperty(ref _selectedProduct, value); + } + public ProductsViewModel() + { + _productService = new ProductService(); + Products = new ObservableCollection(); + AddCommand = new Command(OnAdd); + ShowDetailsCommand = new Command(OnShowDetails); + EditCommand = new Command(OnEdit); + DeleteCommand = new Command(OnDelete); + LoadCategories(); + } + private void LoadCategories() + { + var products = _productService.GetProducts(); + foreach (var product in products) + { + Products.Add(product); + } + } + private void OnAdd() + { + var dialog = new AddProductDialog(); + dialog.Show(); + + } + private void OnShowDetails() + { + + } + private void OnEdit(Product product) + { + + } + private void OnDelete(Product product) + { + + } + + } +} diff --git a/Desktop/Supermarket/Supermarket/Views/HomePage.xaml b/Desktop/Supermarket/Supermarket/Views/HomePage.xaml new file mode 100644 index 0000000..1bd90f5 --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Views/HomePage.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/Desktop/Supermarket/Supermarket/Views/HomePage.xaml.cs b/Desktop/Supermarket/Supermarket/Views/HomePage.xaml.cs new file mode 100644 index 0000000..2e8f28b --- /dev/null +++ b/Desktop/Supermarket/Supermarket/Views/HomePage.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Supermarket.Views +{ + /// + /// Interaction logic for HomePage.xaml + /// + public partial class HomePage : UserControl + { + public HomePage() + { + InitializeComponent(); + } + } +}