diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs new file mode 100644 index 0000000..a1e4440 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.Designer.cs @@ -0,0 +1,547 @@ +// +using System; +using ComputerHardwareStoreDatabaseImplement; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace ComputerHardwareStoreDatabaseImplement.Migrations +{ + [DbContext(typeof(ComputerHardwareStoreDBContext))] + [Migration("20240501130816_fix")] + partial class fix + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "8.0.4") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("VendorId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("VendorId"); + + b.ToTable("Builds"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuildId") + .HasColumnType("integer"); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BuildId"); + + b.HasIndex("ComponentId"); + + b.ToTable("BuildComponents"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuildId") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp without time zone"); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("BuildId"); + + b.ToTable("Comments"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("StoreKeeperId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StoreKeeperId"); + + b.ToTable("Components"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("Sum") + .HasColumnType("double precision"); + + b.HasKey("Id"); + + b.ToTable("Orders"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("OrderId") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("OrderId"); + + b.HasIndex("ProductId"); + + b.ToTable("OrderProducts"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Price") + .HasColumnType("double precision"); + + b.Property("StoreKeeperId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("StoreKeeperId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ComponentId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ComponentId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductComponents"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Cost") + .HasColumnType("double precision"); + + b.Property("DateCreate") + .HasColumnType("timestamp without time zone"); + + b.Property("DateImplement") + .HasColumnType("timestamp without time zone"); + + b.Property("VendorId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("VendorId"); + + b.ToTable("Purchases"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("BuildId") + .HasColumnType("integer"); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("BuildId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseBuilds"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Count") + .HasColumnType("integer"); + + b.Property("ProductId") + .HasColumnType("integer"); + + b.Property("PurchaseId") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("PurchaseId"); + + b.ToTable("PurchaseProducts"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("StoreKeepers"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Login") + .IsRequired() + .HasColumnType("text"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Vendors"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", "Vendor") + .WithMany("Builds") + .HasForeignKey("VendorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Vendor"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.BuildComponent", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") + .WithMany("Components") + .HasForeignKey("BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component") + .WithMany() + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Build"); + + b.Navigation("Component"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Comment", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") + .WithMany() + .HasForeignKey("BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Build"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", "StoreKeeperЗЛ") + .WithMany("Components") + .HasForeignKey("StoreKeeperId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("StoreKeeperЗЛ"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.OrderProduct", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Order", "Order") + .WithMany("Products") + .HasForeignKey("OrderId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Order"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", null) + .WithMany("Products") + .HasForeignKey("StoreKeeperId"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.ProductComponent", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Component", "Component") + .WithMany("ProductComponents") + .HasForeignKey("ComponentId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") + .WithMany("Components") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Component"); + + b.Navigation("Product"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Vendor", null) + .WithMany("Purchases") + .HasForeignKey("VendorId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseBuild", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Build", "Build") + .WithMany() + .HasForeignKey("BuildId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Builds") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Build"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.PurchaseProduct", b => + { + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("ComputerHardwareStoreDatabaseImplement.Models.Purchase", "Purchase") + .WithMany("Products") + .HasForeignKey("PurchaseId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Product"); + + b.Navigation("Purchase"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Build", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Component", b => + { + b.Navigation("ProductComponents"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Order", b => + { + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Product", b => + { + b.Navigation("Components"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Purchase", b => + { + b.Navigation("Builds"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper", b => + { + b.Navigation("Components"); + + b.Navigation("Products"); + }); + + modelBuilder.Entity("ComputerHardwareStoreDatabaseImplement.Models.Vendor", b => + { + b.Navigation("Builds"); + + b.Navigation("Purchases"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs new file mode 100644 index 0000000..8c1a376 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreDatabaseImplement/Migrations/20240501130816_fix.cs @@ -0,0 +1,80 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ComputerHardwareStoreDatabaseImplement.Migrations +{ + /// + public partial class fix : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Orders_Products_ProductId", + table: "Orders"); + + migrationBuilder.DropIndex( + name: "IX_Orders_ProductId", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "Count", + table: "Orders"); + + migrationBuilder.DropColumn( + name: "ProductId", + table: "Orders"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_BuildId", + table: "Comments", + column: "BuildId"); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_Builds_BuildId", + table: "Comments", + column: "BuildId", + principalTable: "Builds", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_Builds_BuildId", + table: "Comments"); + + migrationBuilder.DropIndex( + name: "IX_Comments_BuildId", + table: "Comments"); + + migrationBuilder.AddColumn( + name: "Count", + table: "Orders", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "ProductId", + table: "Orders", + type: "integer", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Orders_ProductId", + table: "Orders", + column: "ProductId"); + + migrationBuilder.AddForeignKey( + name: "FK_Orders_Products_ProductId", + table: "Orders", + column: "ProductId", + principalTable: "Products", + principalColumn: "Id"); + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/BuildController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/BuildController.cs new file mode 100644 index 0000000..e87ea06 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/BuildController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class BuildController : Controller + { + private readonly ILogger _logger; + private readonly IBuildStorage _storage; + + public BuildController(ILogger logger, IBuildStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] BuildSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] BuildSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] BuildBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] BuildBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] BuildBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/CommentController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/CommentController.cs new file mode 100644 index 0000000..07aab60 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/CommentController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class CommentController : Controller + { + private readonly ILogger _logger; + private readonly ICommentStorage _storage; + + public CommentController(ILogger logger, ICommentStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] CommentSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] CommentSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] CommentBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] CommentBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] CommentBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/OrderController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/OrderController.cs new file mode 100644 index 0000000..fb47f10 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/OrderController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class OrderController : Controller + { + private readonly ILogger _logger; + private readonly IOrderStorage _storage; + + public OrderController(ILogger logger, IOrderStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] OrderSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] OrderSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] OrderBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] OrderBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] OrderBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs new file mode 100644 index 0000000..33c5916 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/ProductController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class ProductController : Controller + { + private readonly ILogger _logger; + private readonly IProductStorage _storage; + + public ProductController(ILogger logger, IProductStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] ProductSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] ProductSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] ProductBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/PurchaseController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/PurchaseController.cs new file mode 100644 index 0000000..81238e8 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/PurchaseController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class PurchaseController : Controller + { + private readonly ILogger _logger; + private readonly IPurchaseStorage _storage; + + public PurchaseController(ILogger logger, IPurchaseStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] PurchaseSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] PurchaseSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] PurchaseBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] PurchaseBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] PurchaseBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs new file mode 100644 index 0000000..fb2b5b2 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs @@ -0,0 +1,88 @@ +using Microsoft.AspNetCore.Mvc; +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class StoreKeepersController : Controller + { + private readonly ILogger _logger; + private readonly IStoreKeeperStorage _storage; + + public StoreKeepersController(ILogger logger, IStoreKeeperStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] StoreKeeperSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] StoreKeeperSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] StoreKeeperBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] StoreKeeperBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] StoreKeeperBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs new file mode 100644 index 0000000..3e21627 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs @@ -0,0 +1,87 @@ +using ComputerHardwareStoreContracts.BindingModels; +using ComputerHardwareStoreContracts.SearchModels; +using ComputerHardwareStoreContracts.StorageContracts; +using Microsoft.AspNetCore.Mvc; + +namespace ComputerHardwareStoreREST.Controllers +{ + [ApiController] + [Route("[controller]")] + public class VendorController : Controller + { + private readonly ILogger _logger; + private readonly IVendorStorage _storage; + + public VendorController(ILogger logger, IVendorStorage storage) + { + _logger = logger; + _storage = storage; + } + + [HttpPost("get/filter")] + public IActionResult GetByFilter([FromBody] VendorSearchModel model) + { + try + { + var result = _storage.GetFilteredList(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("get")] + public IActionResult GetById([FromBody] VendorSearchModel model) + { + try + { + var result = _storage.GetElement(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("create")] + public IActionResult Create([FromBody] VendorBindingModel model) + { + try + { + var result = _storage.Insert(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPut("update")] + public IActionResult Update([FromBody] VendorBindingModel model) + { + try + { + var result = _storage.Update(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost("delete")] + public IActionResult Delete([FromBody] VendorBindingModel model) + { + try + { + var result = _storage.Delete(model); + return Ok(result); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + } +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/Shared/_ValidationScriptsPartial.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/Shared/_ValidationScriptsPartial.cshtml new file mode 100644 index 0000000..ed86611 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/Shared/_ValidationScriptsPartial.cshtml @@ -0,0 +1,18 @@ + + + + + + + + diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Create.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Create.cshtml new file mode 100644 index 0000000..3a0573d --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Create.cshtml @@ -0,0 +1,43 @@ +@model ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper + +@{ + ViewData["Title"] = "Create"; +} + +

Create

+ +

StoreKeeper

+
+
+
+
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Delete.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Delete.cshtml new file mode 100644 index 0000000..e6550aa --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Delete.cshtml @@ -0,0 +1,39 @@ +@model ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper + +@{ + ViewData["Title"] = "Delete"; +} + +

Delete

+ +

Are you sure you want to delete this?

+
+

StoreKeeper

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.Login) +
+
+ @Html.DisplayFor(model => model.Login) +
+
+ @Html.DisplayNameFor(model => model.Password) +
+
+ @Html.DisplayFor(model => model.Password) +
+
+ +
+ + | + Back to List +
+
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Details.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Details.cshtml new file mode 100644 index 0000000..5e70222 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Details.cshtml @@ -0,0 +1,36 @@ +@model ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper + +@{ + ViewData["Title"] = "Details"; +} + +

Details

+ +
+

StoreKeeper

+
+
+
+ @Html.DisplayNameFor(model => model.Name) +
+
+ @Html.DisplayFor(model => model.Name) +
+
+ @Html.DisplayNameFor(model => model.Login) +
+
+ @Html.DisplayFor(model => model.Login) +
+
+ @Html.DisplayNameFor(model => model.Password) +
+
+ @Html.DisplayFor(model => model.Password) +
+
+
+ diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Edit.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Edit.cshtml new file mode 100644 index 0000000..78a91aa --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Edit.cshtml @@ -0,0 +1,44 @@ +@model ComputerHardwareStoreDatabaseImplement.Models.StoreKeeper + +@{ + ViewData["Title"] = "Edit"; +} + +

Edit

+ +

StoreKeeper

+
+
+
+
+
+ +
+ + + +
+
+ + + +
+
+ + + +
+
+ +
+
+
+
+ + + +@section Scripts { + @{await Html.RenderPartialAsync("_ValidationScriptsPartial");} +} diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Index.cshtml b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Index.cshtml new file mode 100644 index 0000000..71fa0f7 --- /dev/null +++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Views/StoreKeepers/Index.cshtml @@ -0,0 +1,47 @@ +@model IEnumerable + +@{ + ViewData["Title"] = "Index"; +} + +

Index

+ +

+ Create New +

+ + + + + + + + + + +@foreach (var item in Model) { + + + + + + +} + +
+ @Html.DisplayNameFor(model => model.Name) + + @Html.DisplayNameFor(model => model.Login) + + @Html.DisplayNameFor(model => model.Password) +
+ @Html.DisplayFor(modelItem => item.Name) + + @Html.DisplayFor(modelItem => item.Login) + + @Html.DisplayFor(modelItem => item.Password) + + Edit | + Details | + Delete +