diff --git a/BusinessLogic/BusinessLogic/SellLogic.cs b/BusinessLogic/BusinessLogic/SellLogic.cs new file mode 100644 index 0000000..9561f4f --- /dev/null +++ b/BusinessLogic/BusinessLogic/SellLogic.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BusinessLogic.BusinessLogic +{ + internal class SellLogic + { + } +} diff --git a/Contracts/BindingModels/PurchaseBindingModel.cs b/Contracts/BindingModels/PurchaseBindingModel.cs index 14433e7..a245f47 100644 --- a/Contracts/BindingModels/PurchaseBindingModel.cs +++ b/Contracts/BindingModels/PurchaseBindingModel.cs @@ -12,8 +12,8 @@ namespace Contracts.BindingModels { public Guid Id { get; set; } public DateTime DatePurchase { get; set; } - public required IUser User { get; set; } - public required List Products { get; set; } + public Guid UserId { get; set; } public PurchaseStatus Status { get; set; } + public Dictionary PurchaseProducts { get; set; } = new(); } } diff --git a/Contracts/Converters/PurchaseConverter.cs b/Contracts/Converters/PurchaseConverter.cs index 1b181f5..c2139b8 100644 --- a/Contracts/Converters/PurchaseConverter.cs +++ b/Contracts/Converters/PurchaseConverter.cs @@ -14,16 +14,16 @@ namespace Contracts.Converters { Id = model.Id, DatePurchase = model.DatePurchase, - User = model.User, - Products = model.Products, + UserId = model.UserId, + PurchaseProducts = model.PurchaseProducts, }; public static PurchaseBindingModel ToBinding(PurchaseViewModel model) => new() { Id = model.Id, DatePurchase = model.DatePurchase, - User = model.User, - Products = model.Products, + UserId = model.UserId, + PurchaseProducts = model.PurchaseProducts, }; } } diff --git a/Contracts/Converters/SellConverter.cs b/Contracts/Converters/SellConverter.cs new file mode 100644 index 0000000..556c9b1 --- /dev/null +++ b/Contracts/Converters/SellConverter.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Contracts.Converters +{ + public class SellConverter + { + + } +} diff --git a/Contracts/ViewModels/PurchaseViewModel.cs b/Contracts/ViewModels/PurchaseViewModel.cs index b14933c..49b448f 100644 --- a/Contracts/ViewModels/PurchaseViewModel.cs +++ b/Contracts/ViewModels/PurchaseViewModel.cs @@ -12,8 +12,9 @@ namespace Contracts.ViewModels { public Guid Id { get; set; } public DateTime DatePurchase { get; set; } - public required IUser User { get; set; } - public required List Products { get; set; } + public required Guid UserId { get; set; } public PurchaseStatus Status { get; set; } - } + public Dictionary PurchaseProducts { get; set; } = new() + + } } diff --git a/DatabaseImplement/Implements/SellStorage.cs b/DatabaseImplement/Implements/SellStorage.cs index aeac65f..533486d 100644 --- a/DatabaseImplement/Implements/SellStorage.cs +++ b/DatabaseImplement/Implements/SellStorage.cs @@ -13,8 +13,8 @@ namespace DatabaseImplement.Implements { public SellBindingModel? Delete(SellSearchModel model) { - - } + throw new NotImplementedException(); + } public SellBindingModel? GetElement(SellSearchModel model) { diff --git a/DatabaseImplement/Models/Product.cs b/DatabaseImplement/Models/Product.cs index 7edb9f4..7831de3 100644 --- a/DatabaseImplement/Models/Product.cs +++ b/DatabaseImplement/Models/Product.cs @@ -83,7 +83,6 @@ namespace DatabaseImplement.Models IsBeingSold = model.IsBeingSold; Amount = model.Amount; } - public ProductViewModel GetViewModel { get diff --git a/DatabaseImplement/Models/Purchase.cs b/DatabaseImplement/Models/Purchase.cs index 5430b34..35e9041 100644 --- a/DatabaseImplement/Models/Purchase.cs +++ b/DatabaseImplement/Models/Purchase.cs @@ -2,10 +2,13 @@ using Contracts.ViewModels; using DataModels.Enums; using DataModels.Models; +using Microsoft.EntityFrameworkCore.Metadata.Internal; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; @@ -16,25 +19,63 @@ namespace DatabaseImplement.Models public Guid Id { get; set; } [Required] public DateTime DatePurchase { get; set; } - [Required] - public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown; - public PurchaseBindingModel GetBindingModel() => new() + [Required] + public Guid UserId { get; set; } + [Required] + public PurchaseStatus Status { get; private set; } = PurchaseStatus.Unknown; + private Dictionary? _purchaseProducts = null; + public virtual User? User { get; set; } + [DataMember] + [NotMapped] + public Dictionary PurchaseProducts + { + get + { + if (_purchaseProducts == null) + { + _purchaseProducts = Products.ToDictionary(e => e.ProductId, e => (e.Product as IProduct, e.Count)); + } + return _purchaseProducts; + } + set { } + } + [ForeignKey("PurchaseId")] + public virtual List Products { get; set; } = new(); + public PurchaseBindingModel GetBindingModel() => new() { Id = Id, - DatePurchase = DatePurchase + DatePurchase = DatePurchase, + UserId = UserId, + PurchaseProducts = PurchaseProducts, + Status = Status }; - public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() + public PurchaseViewModel GetViewModel() => new() + { + Id = Id, + DatePurchase = DatePurchase, + UserId = UserId, + PurchaseProducts = PurchaseProducts, + Status = Status + }; + + public static Purchase ToPurchaseFromView(PurchaseViewModel model, Purchase purchase) => new() { Id = model.Id, - DatePurchase = model.DatePurchase - }; + DatePurchase = model.DatePurchase, + UserId = model.UserId, + PurchaseProducts = model.PurchaseProducts, + Status = model.Status + }; public static Purchase ToPurchaseFromBinding(PurchaseBindingModel model, Purchase purchase) => new() { Id = model.Id, DatePurchase = model.DatePurchase, - }; + UserId = model.UserId, + PurchaseProducts = model.PurchaseProducts, + Status = model.Status + }; public void Update(PurchaseBindingModel model, Purchase purchase) { diff --git a/DatabaseImplement/Models/PurchaseProducts.cs b/DatabaseImplement/Models/PurchaseProducts.cs new file mode 100644 index 0000000..2097d38 --- /dev/null +++ b/DatabaseImplement/Models/PurchaseProducts.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DatabaseImplement.Models +{ + public class PurchaseProducts + { + public Guid Guid { get; set; } + [Required] + public Guid PurchaseId { get; set; } + [Required] + public Guid ProductId { get; set; } + [Required] + public int Count { get; set; } + public virtual Product Product { get; set; } = new(); + public virtual Purchase Purchase { get; set; } = new(); + + } +} diff --git a/WebApp/Pages/Cart.cshtml b/WebApp/Pages/Cart.cshtml new file mode 100644 index 0000000..32f767e --- /dev/null +++ b/WebApp/Pages/Cart.cshtml @@ -0,0 +1,4 @@ +@page +@model WebApp.Pages.CartModel +@{ +} \ No newline at end of file diff --git a/WebApp/Pages/Cart.cshtml.cs b/WebApp/Pages/Cart.cshtml.cs new file mode 100644 index 0000000..deab2d3 --- /dev/null +++ b/WebApp/Pages/Cart.cshtml.cs @@ -0,0 +1,13 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages +{ + public class CartModel : PageModel + { + public void OnGet() + { + + } + } +} diff --git a/WebApp/Pages/Catalog.cshtml b/WebApp/Pages/Catalog.cshtml new file mode 100644 index 0000000..7aac31b --- /dev/null +++ b/WebApp/Pages/Catalog.cshtml @@ -0,0 +1,4 @@ +@page +@model WebApp.Pages.CatalogModel +@{ +} diff --git a/WebApp/Pages/Catalog.cshtml.cs b/WebApp/Pages/Catalog.cshtml.cs new file mode 100644 index 0000000..23f920a --- /dev/null +++ b/WebApp/Pages/Catalog.cshtml.cs @@ -0,0 +1,12 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace WebApp.Pages +{ + public class CatalogModel : PageModel + { + public void OnGet() + { + } + } +}