This commit is contained in:
Илья Федотов 2024-06-01 06:31:02 +04:00
parent a65793b2c2
commit 5d9c5122d4
10 changed files with 36 additions and 43 deletions

View File

@ -36,7 +36,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
_logger.LogInformation($"ReadElement.ProductID:{model.ProductID}.ID:{model.ID}"); _logger.LogInformation($"ReadElement.ID:{model.ID}");
var element = _storage.GetElement(model); var element = _storage.GetElement(model);
if (element == null) if (element == null)
{ {
@ -47,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return element; return element;
} }
public List<PaymeantViewModel>? ReadList(PaymeantSearchModel? model) public List<PaymeantViewModel> ReadList(PaymeantSearchModel? model)
{ {
_logger.LogInformation($"ReadList. ClientID:{model?.ID}"); _logger.LogInformation($"ReadList. ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ; var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
@ -57,7 +57,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return null; return null;
} }
_logger.LogInformation($"ReadList.Count:{list.Count}"); _logger.LogInformation($"ReadList.Count:{list.Count}");
return null; return list;
} }

View File

@ -9,7 +9,6 @@ namespace ElectronicsShopContracts.SearchModels
public class PaymeantSearchModel public class PaymeantSearchModel
{ {
public int? ID { get; set; } public int? ID { get; set; }
public int? ProductID { get; set; }
public int? OrderID { get; set; } public int? OrderID { get; set; }
public double? SumPay { get; set; } public double? SumPay { get; set; }
public int? ClientID { get; set; } public int? ClientID { get; set; }

View File

@ -12,7 +12,7 @@ namespace ElectronicsShopContracts.StorageContracts
public interface IPaymeantStorage public interface IPaymeantStorage
{ {
List<PaymeantViewModel>? GetFullList(); List<PaymeantViewModel>? GetFullList();
List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model); List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model);
PaymeantViewModel? GetElement(PaymeantSearchModel model); PaymeantViewModel? GetElement(PaymeantSearchModel model);
PaymeantViewModel? Insert(PaymeantBindingModel model); PaymeantViewModel? Insert(PaymeantBindingModel model);

View File

@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
optionsBuilder) optionsBuilder)
{ {
if (optionsBuilder.IsConfigured == false) { if (optionsBuilder.IsConfigured == false) {
optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-E2VPEN3\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True"); optionsBuilder.UseSqlServer(@"Data Source=DESKTOP-O0N00SH\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
} }
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
} }

View File

@ -3,6 +3,7 @@ using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts; using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels; using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataBaseImplement.Models; using ElectronicsShopDataBaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -36,26 +37,14 @@ namespace ElectronicsShopDataBaseImplement.Implements {
} }
public PaymeantViewModel? GetElement(PaymeantSearchModel model) { public PaymeantViewModel? GetElement(PaymeantSearchModel model) {
if (model.ProductID.HasValue || model.OrderID.HasValue) {
return null;
}
using var context = new Database(); using var context = new Database();
return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel; return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
} }
public List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model) { public List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model) {
if (model.ProductID.HasValue || model.OrderID.HasValue) {
return new();
}
using var context = new Database(); using var context = new Database();
if (model.ClientID.HasValue) {
return context.Paymeants
.Where(x => x.ClientID == model.ClientID)
.Select(x => x.GetViewModel).ToList();
}
return context.Paymeants return context.Paymeants
.Where(x => x.ID == model.ID) .Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
.Select(x => x.GetViewModel).ToList();
} }
public List<PaymeantViewModel>? GetFullList() { public List<PaymeantViewModel>? GetFullList() {

View File

@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasKey("ID"); b.HasKey("ID");
b.ToTable("Clients"); b.ToTable("Clients", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
@ -72,7 +72,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("EmployeeID"); b.HasIndex("EmployeeID");
b.ToTable("CostItems"); b.ToTable("CostItems", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
@ -97,7 +97,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasKey("ID"); b.HasKey("ID");
b.ToTable("Employees"); b.ToTable("Employees", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b =>
@ -127,7 +127,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("ClientID"); b.HasIndex("ClientID");
b.ToTable("Messages"); b.ToTable("Messages", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
@ -151,7 +151,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("ClientID"); b.HasIndex("ClientID");
b.ToTable("Orders"); b.ToTable("Orders", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
@ -177,7 +177,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("ProductID"); b.HasIndex("ProductID");
b.ToTable("OrderProducts"); b.ToTable("OrderProducts", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
@ -207,7 +207,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("PaymentID"); b.HasIndex("PaymentID");
b.ToTable("Paymeants"); b.ToTable("Paymeants", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
@ -232,7 +232,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
b.HasIndex("CostItemID"); b.HasIndex("CostItemID");
b.ToTable("Products"); b.ToTable("Products", (string)null);
}); });
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b => modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>

View File

@ -20,7 +20,7 @@ namespace ElectronicsShopDataBaseImplement.Models
[ForeignKey("OrderID")] [ForeignKey("OrderID")]
public int OrderID { get; set; } public int OrderID { get; set; }
[Required] [ForeignKey("ClientID")]
public int ClientID { get; set; } public int ClientID { get; set; }
[Required] [Required]

View File

@ -57,7 +57,7 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
} }
[HttpPost] [HttpGet]
public void CreatePaymeant (PaymeantBindingModel model) { public void CreatePaymeant (PaymeantBindingModel model) {
try { try {
_payLogic.CreatePay(model); _payLogic.CreatePay(model);
@ -66,16 +66,5 @@ namespace ElectronicsShopRestAPI.Controllers {
_logger.LogError(ex, "Ошибка создания оплаты"); _logger.LogError(ex, "Ошибка создания оплаты");
} }
} }
[HttpPost]
public List<PaymeantViewModel>? GetPaymeants(int _clientID) {
try {
return _payLogic.ReadList(new PaymeantSearchModel { ClientID = _clientID });
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения списка оплат клиента id = {_clientID}");
throw;
}
}
} }
} }

View File

@ -18,16 +18,18 @@ namespace ElectronicsShopRestAPI.Controllers {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IProductLogic _product; private readonly IProductLogic _product;
private readonly IOrderLogic _order; private readonly IOrderLogic _order;
private readonly IPaymeantLogic _paymeant;
//private readonly IMessageInfoLogic _message; //private readonly IMessageInfoLogic _message;
private Dictionary<int, (IProductModel, int)> _productlist; private Dictionary<int, (IProductModel, int)> _productlist;
public MainController(ILogger<MainController> logger, IProductLogic product, public MainController(ILogger<MainController> logger, IProductLogic product,
IOrderLogic orderLogic) { IOrderLogic orderLogic, IPaymeantLogic paymeant) {
_logger = logger; _logger = logger;
_product = product; _product = product;
_order = orderLogic; _order = orderLogic;
_productlist = new Dictionary<int, (IProductModel, int)>(); _productlist = new Dictionary<int, (IProductModel, int)>();
_paymeant = paymeant;
} }
[HttpGet] [HttpGet]
@ -220,5 +222,16 @@ namespace ElectronicsShopRestAPI.Controllers {
} }
return ans; return ans;
} }
[HttpPost]
public List<PaymeantViewModel>? GetPaymeants(int _clientID) {
try {
return _paymeant.ReadList(new PaymeantSearchModel { ClientID = _clientID });
}
catch (Exception ex) {
_logger.LogError(ex, $"Ошибка получения списка оплат клиента id = {_clientID}");
throw;
}
}
} }
} }

View File

@ -25,11 +25,14 @@ namespace ElectronicsShopUserApp.Controllers {
_productList = new Dictionary<int, (IProductModel, int)>(); _productList = new Dictionary<int, (IProductModel, int)>();
} }
[HttpGet]
public IActionResult Index() { public IActionResult Index() {
if (APIClient.Client == null) { if (APIClient.Client == null) {
return Redirect("~/Home/Enter"); return Redirect("~/Home/Enter");
} }
return View(APIClient.GetRequset<List<PaymeantViewModel>>($"api/client/getpaymeants?_clientid={APIClient.Client.ID}"));
var view = APIClient.GetRequset<List<PaymeantViewModel>>($"api/main/getpaymeants?_clientid={APIClient.Client.ID}");
return View(view);
} }
[HttpGet] [HttpGet]