diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs deleted file mode 100644 index 18b9efb..0000000 --- a/Bookshop/BookshopBusinessLogic/BusinessLogics/InstanceLogic.cs +++ /dev/null @@ -1,112 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BookshopContracts.BindingModels; -using BookshopContracts.SearchModels; -using BookshopContracts.ViewModels; -using BookshopContracts.BusinessLogicsContracts; -using BookshopContracts.StorageContracts; -using Microsoft.Extensions.Logging; - -namespace BookshopBusinessLogic.BusinessLogics -{ - public class InstanceLogic : IInstanceLogic - { - private readonly ILogger _logger; - - private readonly IInstanceStorage _InstanceStorage; - - public InstanceLogic(ILogger logger, IInstanceStorage InstanceStorage) - { - _logger = logger; - _InstanceStorage = InstanceStorage; - } - - public List? ReadList(InstanceSearchModel? model) - { - _logger.LogInformation("ReadList. BookId:{BookId}. Id:{Id}", model?.BookId, model?.Id); - var list = model == null ? _InstanceStorage.GetFullList() : _InstanceStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - public InstanceViewModel? ReadElement(InstanceSearchModel model) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - _logger.LogInformation("ReadElement. BookId:{BookId}. Id:{Id}", model.BookId, model.Id); - var element = _InstanceStorage.GetElement(model); - if (element == null) - { - _logger.LogWarning("ReadElement element not found"); - return null; - } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); - return element; - } - - public bool Create(InstanceBindingModel model) - { - CheckModel(model); - if (_InstanceStorage.Insert(model) == null) - { - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool Update(InstanceBindingModel model) - { - CheckModel(model); - if (_InstanceStorage.Update(model) == null) - { - _logger.LogWarning("Update operation failed"); - return false; - } - return true; - } - - public bool Delete(InstanceBindingModel model) - { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_InstanceStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; - } - - private void CheckModel(InstanceBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.StockQuantity <= 0) - { - throw new ArgumentNullException("Количество экзмепляров должно быть больше 0", nameof(model.StockQuantity)); - } - if (model.Price <= 0) - { - throw new ArgumentNullException("Цена книги должна быть больше 0", nameof(model.Price)); - } - _logger.LogInformation("Instance. Id:{Id}", model.Id); - } - } -} diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs index faad434..bf32cf1 100644 --- a/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/OrderLogic.cs @@ -100,9 +100,9 @@ namespace BookshopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Количество книг в заказе должно быть больше 0", nameof(model.Quantity)); } - if (model.InstanceId <= 0) + if (model.BookId <= 0) { - throw new ArgumentNullException("Не указан идентификатор экземляра", nameof(model.InstanceId)); + throw new ArgumentNullException("Не указан идентификатор книги", nameof(model.BookId)); } if (model.UserId <= 0) { diff --git a/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs b/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs index ec6e96a..1d75f44 100644 --- a/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs +++ b/Bookshop/BookshopBusinessLogic/BusinessLogics/ReviewLogic.cs @@ -100,9 +100,9 @@ namespace BookshopBusinessLogic.BusinessLogics { throw new ArgumentNullException("Нет текста отзыва", nameof(model.ReviewText)); } - if (model.InstanceId <= 0) + if (model.BookId <= 0) { - throw new ArgumentNullException("Не указан идентификатор экземляра", nameof(model.InstanceId)); + throw new ArgumentNullException("Не указан идентификатор книги", nameof(model.BookId)); } if (model.UserId <= 0) { diff --git a/Bookshop/BookshopContracts/BindingModels/InstanceBindingModel.cs b/Bookshop/BookshopContracts/BindingModels/InstanceBindingModel.cs deleted file mode 100644 index 4cd1f2d..0000000 --- a/Bookshop/BookshopContracts/BindingModels/InstanceBindingModel.cs +++ /dev/null @@ -1,19 +0,0 @@ -using BookshopDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BookshopContracts.BindingModels -{ - public class InstanceBindingModel : IInstanceModel - { - public int Id { get; set; } - public bool Pictures { get; set; } - public int StockQuantity { get; set; } - public double Price { get; set; } - public int BookId { get; set; } - public int PublisherId { get; set; } - } -} diff --git a/Bookshop/BookshopContracts/BindingModels/OrderBindingModel.cs b/Bookshop/BookshopContracts/BindingModels/OrderBindingModel.cs index d664ece..259d8b7 100644 --- a/Bookshop/BookshopContracts/BindingModels/OrderBindingModel.cs +++ b/Bookshop/BookshopContracts/BindingModels/OrderBindingModel.cs @@ -12,7 +12,7 @@ namespace BookshopContracts.BindingModels public int Id { get; set; } public DateTime OrderDate { get; set; } public int Quantity { get; set; } - public int InstanceId { get; set; } + public int BookId { get; set; } public int UserId { get; set; } } } diff --git a/Bookshop/BookshopContracts/BindingModels/ReviewBindingModel.cs b/Bookshop/BookshopContracts/BindingModels/ReviewBindingModel.cs index 2cba0a8..a4c5590 100644 --- a/Bookshop/BookshopContracts/BindingModels/ReviewBindingModel.cs +++ b/Bookshop/BookshopContracts/BindingModels/ReviewBindingModel.cs @@ -12,7 +12,7 @@ namespace BookshopContracts.BindingModels public int Id { get; set; } public string ReviewText { get; set; } = string.Empty; public DateTime ReviewDate { get; set; } - public int InstanceId { get; set; } + public int BookId { get; set; } public int UserId { get; set; } } } diff --git a/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs b/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs deleted file mode 100644 index 2bfdee9..0000000 --- a/Bookshop/BookshopContracts/BusinessLogicsContracts/IInstanceLogic.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BookshopContracts.BindingModels; -using BookshopContracts.ViewModels; -using BookshopContracts.SearchModels; - -namespace BookshopContracts.BusinessLogicsContracts -{ - public interface IInstanceLogic - { - List? ReadList(InstanceSearchModel? model); - InstanceViewModel? ReadElement(InstanceSearchModel model); - bool Create(InstanceBindingModel model); - bool Update(InstanceBindingModel model); - bool Delete(InstanceBindingModel model); - } -} diff --git a/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs deleted file mode 100644 index a97ae9c..0000000 --- a/Bookshop/BookshopContracts/SearchModels/InstanceSearchModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BookshopContracts.SearchModels -{ - public class InstanceSearchModel - { - public int? Id { get; set; } - public bool? Pictures { get; set; } - public int? StockQuantity { get; set; } - public double? Price { get; set; } - public int? BookId { get; set; } - public int? PublisherId { get; set; } - } -} diff --git a/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs index bf37752..c4f25f3 100644 --- a/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs +++ b/Bookshop/BookshopContracts/SearchModels/OrderSearchModel.cs @@ -11,7 +11,7 @@ namespace BookshopContracts.SearchModels public int? Id { get; set; } public DateTime? OrderDate { get; set; } public int? Quantity { get; set; } - public int? InstanceId { get; set; } + public int? BookId { get; set; } public int? UserId { get; set; } } } diff --git a/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs b/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs index 857bd47..3e9503b 100644 --- a/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs +++ b/Bookshop/BookshopContracts/SearchModels/ReviewSearchModel.cs @@ -11,7 +11,7 @@ namespace BookshopContracts.SearchModels public int? Id { get; set; } public string? ReviewText { get; set; } = string.Empty; public DateTime? ReviewDate { get; set; } - public int? InstanceId { get; set; } + public int? BookId { get; set; } public int? UserId { get; set; } } } diff --git a/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs b/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs deleted file mode 100644 index 51b0c9c..0000000 --- a/Bookshop/BookshopContracts/StorageContracts/IInstanceStorage.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BookshopContracts.BindingModels; -using BookshopContracts.ViewModels; -using BookshopContracts.SearchModels; - -namespace BookshopContracts.StorageContracts -{ - public interface IInstanceStorage - { - List GetFullList(); - List GetFilteredList(InstanceSearchModel model); - InstanceViewModel? GetElement(InstanceSearchModel model); - InstanceViewModel? Insert(InstanceBindingModel model); - InstanceViewModel? Update(InstanceBindingModel model); - InstanceViewModel? Delete(InstanceBindingModel model); - } -} diff --git a/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs b/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs deleted file mode 100644 index 4781cc9..0000000 --- a/Bookshop/BookshopContracts/ViewModels/InstanceViewModel.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BookshopContracts.ViewModels -{ - public class InstanceViewModel - { - public int Id { get; set; } - [DisplayName("Наличие картинок")] - public bool Pictures { get; set; } - [DisplayName("Количество экземлпяров")] - public int StockQuantity { get; set; } - [DisplayName("Стоимость книги")] - public double Price { get; set; } - public int BookId { get; set; } - public int PublisherId { get; set; } - } -} diff --git a/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs b/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs index 3f08d5c..5334cf9 100644 --- a/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs +++ b/Bookshop/BookshopContracts/ViewModels/OrderViewModel.cs @@ -14,7 +14,7 @@ namespace BookshopContracts.ViewModels public DateTime OrderDate { get; set; } [DisplayName("Количество")] public int Quantity { get; set; } - public int InstanceId { get; set; } + public int BookId { get; set; } public int UserId { get; set; } } } diff --git a/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs b/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs index a7374d8..baf9a46 100644 --- a/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs +++ b/Bookshop/BookshopContracts/ViewModels/ReviewViewModel.cs @@ -14,7 +14,7 @@ namespace BookshopContracts.ViewModels public string ReviewText { get; set; } = string.Empty; [DisplayName("Дата отзыва")] public DateTime ReviewDate { get; set; } - public int InstanceId { get; set; } + public int BookId { get; set; } public int UserId { get; set; } } } diff --git a/Bookshop/BookshopDataModels/Models/IInstanceModel.cs b/Bookshop/BookshopDataModels/Models/IInstanceModel.cs deleted file mode 100644 index a3870e9..0000000 --- a/Bookshop/BookshopDataModels/Models/IInstanceModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BookshopDataModels.Models -{ - public interface IInstanceModel : IId - { - bool Pictures { get; } - int StockQuantity { get; } - double Price { get; } - int BookId { get; } - int PublisherId { get; } - } -} diff --git a/Bookshop/BookshopDataModels/Models/IOrderModel.cs b/Bookshop/BookshopDataModels/Models/IOrderModel.cs index f9f4151..8728f6f 100644 --- a/Bookshop/BookshopDataModels/Models/IOrderModel.cs +++ b/Bookshop/BookshopDataModels/Models/IOrderModel.cs @@ -10,7 +10,7 @@ namespace BookshopDataModels.Models { DateTime OrderDate { get; } int Quantity { get; } - int InstanceId { get; } + int BookId { get; } int UserId { get; } } } diff --git a/Bookshop/BookshopDataModels/Models/IReviewModel.cs b/Bookshop/BookshopDataModels/Models/IReviewModel.cs index b54cf00..9ae2d30 100644 --- a/Bookshop/BookshopDataModels/Models/IReviewModel.cs +++ b/Bookshop/BookshopDataModels/Models/IReviewModel.cs @@ -10,7 +10,7 @@ namespace BookshopDataModels.Models { string ReviewText { get; } DateTime ReviewDate { get; } - int InstanceId { get; } + int BookId { get; } int UserId { get; } } } diff --git a/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs b/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs index 9ea9693..fe6c306 100644 --- a/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs +++ b/Bookshop/BookshopDatabaseImplement/BookshopDatabase.cs @@ -21,7 +21,6 @@ namespace BookshopDatabaseImplement public virtual DbSet Authors { set; get; } public virtual DbSet Books { set; get; } public virtual DbSet Genres { set; get; } - public virtual DbSet Instances { set; get; } public virtual DbSet Orders { set; get; } public virtual DbSet Publishers { set; get; } public virtual DbSet Reviews { set; get; } diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs deleted file mode 100644 index 9354cb2..0000000 --- a/Bookshop/BookshopDatabaseImplement/Implemets/InstanceStorage.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using BookshopContracts.StorageContracts; -using BookshopContracts.ViewModels; -using BookshopContracts.SearchModels; -using BookshopContracts.BindingModels; -using BookshopDatabaseImplement.Models; -using Microsoft.EntityFrameworkCore; - -namespace BookshopDatabaseImplement.Implemets -{ - public class InstanceStorage : IInstanceStorage - { - public List GetFullList() - { - using var context = new BookshopDatabase(); - return context.Instances - .Include(x => x.Book) - .Include(x => x.Publisher) - .Select(x => x.GetViewModel) - .ToList(); - } - - public List GetFilteredList(InstanceSearchModel model) - { - if (string.IsNullOrEmpty(model.Title)) - { - return new(); - } - using var context = new BookshopDatabase(); - return context.Instances - .Include(x => x.Author) - .Include(x => x.Genre) - .Where(x => x.Title.Contains(model.Title)) - .Select(x => x.GetViewModel) - .ToList(); - } - - public InstanceViewModel? GetElement(InstanceSearchModel model) - { - if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) - { - return null; - } - using var context = new BookshopDatabase(); - return context.Instances - .Include(x => x.Author) - .Include(x => x.Genre) - .FirstOrDefault(x => x.Id.Equals(model.Id)) - ?.GetViewModel; - } - - public InstanceViewModel? Insert(InstanceBindingModel model) - { - var newInstance = Instance.Create(model); - if (newInstance == null) - { - return null; - } - using var context = new BookshopDatabase(); - context.Instances.Add(newInstance); - context.SaveChanges(); - return newInstance.GetViewModel; - } - - public InstanceViewModel? Update(InstanceBindingModel model) - { - using var context = new BookshopDatabase(); - var client = context.Instances.FirstOrDefault(x => x.Id == model.Id); - if (client == null) - { - return null; - } - client.Update(model); - context.SaveChanges(); - return client.GetViewModel; - } - - public InstanceViewModel? Delete(InstanceBindingModel model) - { - using var context = new BookshopDatabase(); - var element = context.Instances.FirstOrDefault(x => x.Id == model.Id); - if (element != null) - { - context.Instances.Remove(element); - context.SaveChanges(); - return element.GetViewModel; - } - return null; - } - } -} diff --git a/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs b/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs index fb3f6f3..b07926d 100644 --- a/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs +++ b/Bookshop/BookshopDatabaseImplement/Implemets/OrderStorage.cs @@ -8,10 +8,88 @@ using BookshopContracts.ViewModels; using BookshopContracts.SearchModels; using BookshopContracts.BindingModels; using BookshopDatabaseImplement.Models; +using Microsoft.EntityFrameworkCore; namespace BookshopDatabaseImplement.Implemets { - internal class OrderStorage + public class OrderStorage : IOrderStorage { + public List GetFullList() + { + using var context = new BookshopDatabase(); + return context.Orders + .Include(x => x.Author) + .Include(x => x.Genre) + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (string.IsNullOrEmpty(model.Title)) + { + return new(); + } + using var context = new BookshopDatabase(); + return context.Orders + .Include(x => x.Author) + .Include(x => x.Genre) + .Where(x => x.Title.Contains(model.Title)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (string.IsNullOrEmpty(model.Title) && !model.Id.HasValue) + { + return null; + } + using var context = new BookshopDatabase(); + return context.Orders + .Include(x => x.Author) + .Include(x => x.Genre) + .FirstOrDefault(x => x.Id.Equals(model.Id)) + ?.GetViewModel; + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + using var context = new BookshopDatabase(); + context.Orders.Add(newOrder); + context.SaveChanges(); + return newOrder.GetViewModel; + } + + public OrderViewModel? Update(OrderBindingModel model) + { + using var context = new BookshopDatabase(); + var client = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (client == null) + { + return null; + } + client.Update(model); + context.SaveChanges(); + return client.GetViewModel; + } + + public OrderViewModel? Delete(OrderBindingModel model) + { + using var context = new BookshopDatabase(); + var element = context.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + context.Orders.Remove(element); + context.SaveChanges(); + return element.GetViewModel; + } + return null; + } } } diff --git a/Bookshop/BookshopDatabaseImplement/Models/Instance.cs b/Bookshop/BookshopDatabaseImplement/Models/Instance.cs deleted file mode 100644 index 42f94bc..0000000 --- a/Bookshop/BookshopDatabaseImplement/Models/Instance.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.ComponentModel.DataAnnotations.Schema; -using BookshopDataModels.Models; -using System.ComponentModel.DataAnnotations; -using BookshopContracts.BindingModels; -using BookshopContracts.ViewModels; -using System.Diagnostics.Metrics; - -namespace BookshopDatabaseImplement.Models -{ - public class Instance : IInstanceModel - { - public int Id { get; private set; } - [Required] - public bool Pictures { get; private set; } - [Required] - public int StockQuantity { get; private set; } - [Required] - public double Price { get; private set; } - [ForeignKey("BookId")] - public int BookId { get; private set; } - public virtual Book Book { get; private set; } = new(); - [ForeignKey("PublisherId")] - public int PublisherId { get; private set; } - public virtual Publisher Publisher { get; private set; } = new(); - public static Instance? Create(InstanceBindingModel model) - { - if (model == null) - { - return null; - } - return new() - { - Id = model.Id, - Pictures = model.Pictures, - StockQuantity = model.StockQuantity, - Price = model.Price, - BookId = model.BookId, - PublisherId = model.PublisherId - }; - } - public void Update(InstanceBindingModel model) - { - if (model == null) - { - return; - } - Pictures = model.Pictures; - StockQuantity = model.StockQuantity; - Price = model.Price; - BookId = model.BookId; - PublisherId = model.PublisherId; - } - public InstanceViewModel GetViewModel => new() - { - Id = Id, - Pictures = Pictures, - StockQuantity = StockQuantity, - Price = Price, - BookId = BookId, - PublisherId=PublisherId - }; - } -} diff --git a/Bookshop/BookshopDatabaseImplement/Models/Order.cs b/Bookshop/BookshopDatabaseImplement/Models/Order.cs index 38d0990..8579a7b 100644 --- a/Bookshop/BookshopDatabaseImplement/Models/Order.cs +++ b/Bookshop/BookshopDatabaseImplement/Models/Order.cs @@ -20,9 +20,9 @@ namespace BookshopDatabaseImplement.Models public DateTime OrderDate { get; private set; } [Required] public int Quantity { get; private set; } - [ForeignKey("InstanceId")] - public int InstanceId { get; private set; } - public virtual Instance Instance { get; private set; } = new(); + [ForeignKey("BookId")] + public int BookId { get; private set; } + public virtual Book Book { get; private set; } = new(); [ForeignKey("UserId")] public int UserId { get; private set; } public virtual User User { get; private set; } = new(); @@ -37,7 +37,7 @@ namespace BookshopDatabaseImplement.Models Id = model.Id, OrderDate = model.OrderDate, Quantity = model.Quantity, - InstanceId = model.InstanceId, + BookId = model.BookId, UserId = model.UserId }; } @@ -49,7 +49,7 @@ namespace BookshopDatabaseImplement.Models } OrderDate = model.OrderDate; Quantity = model.Quantity; - InstanceId = model.InstanceId; + BookId = model.BookId; UserId = model.UserId; } public OrderViewModel GetViewModel => new() @@ -57,7 +57,7 @@ namespace BookshopDatabaseImplement.Models Id = Id, OrderDate = OrderDate, Quantity = Quantity, - InstanceId = InstanceId, + BookId = BookId, UserId = UserId }; } diff --git a/Bookshop/BookshopDatabaseImplement/Models/Review.cs b/Bookshop/BookshopDatabaseImplement/Models/Review.cs index 5d14292..9f2331e 100644 --- a/Bookshop/BookshopDatabaseImplement/Models/Review.cs +++ b/Bookshop/BookshopDatabaseImplement/Models/Review.cs @@ -19,9 +19,9 @@ namespace BookshopDatabaseImplement.Models public string ReviewText { get; private set; } = string.Empty; [Required] public DateTime ReviewDate { get; private set; } - [ForeignKey("InstanceId")] - public int InstanceId { get; private set; } - public virtual Instance Instance { get; private set; } = new(); + [ForeignKey("BookId")] + public int BookId { get; private set; } + public virtual Book Book { get; private set; } = new(); [ForeignKey("UserId")] public int UserId { get; private set; } public virtual User User { get; private set; } = new(); @@ -36,7 +36,7 @@ namespace BookshopDatabaseImplement.Models Id = model.Id, ReviewText = model.ReviewText, ReviewDate = model.ReviewDate, - InstanceId = model.InstanceId, + BookId = model.BookId, UserId = model.UserId, }; } @@ -48,7 +48,7 @@ namespace BookshopDatabaseImplement.Models } ReviewText = model.ReviewText; ReviewDate = model.ReviewDate; - InstanceId = model.InstanceId; + BookId = model.BookId; UserId = model.UserId; } public ReviewViewModel GetViewModel => new() @@ -56,7 +56,7 @@ namespace BookshopDatabaseImplement.Models Id = Id, ReviewText = ReviewText, ReviewDate = ReviewDate, - InstanceId = InstanceId, + BookId = BookId, UserId = UserId }; }