1
This commit is contained in:
parent
a65793b2c2
commit
5d9c5122d4
@ -36,7 +36,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
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);
|
||||
if (element == null)
|
||||
{
|
||||
@ -47,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return element;
|
||||
}
|
||||
|
||||
public List<PaymeantViewModel>? ReadList(PaymeantSearchModel? model)
|
||||
public List<PaymeantViewModel> ReadList(PaymeantSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
|
||||
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
|
||||
@ -57,7 +57,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation($"ReadList.Count:{list.Count}");
|
||||
return null;
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ namespace ElectronicsShopContracts.SearchModels
|
||||
public class PaymeantSearchModel
|
||||
{
|
||||
public int? ID { get; set; }
|
||||
public int? ProductID { get; set; }
|
||||
public int? OrderID { get; set; }
|
||||
public double? SumPay { get; set; }
|
||||
public int? ClientID { get; set; }
|
||||
|
@ -12,7 +12,7 @@ namespace ElectronicsShopContracts.StorageContracts
|
||||
public interface IPaymeantStorage
|
||||
{
|
||||
List<PaymeantViewModel>? GetFullList();
|
||||
List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model);
|
||||
List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model);
|
||||
PaymeantViewModel? GetElement(PaymeantSearchModel model);
|
||||
|
||||
PaymeantViewModel? Insert(PaymeantBindingModel model);
|
||||
|
@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
|
||||
optionsBuilder)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.StorageContracts;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using ElectronicsShopDataBaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -36,26 +37,14 @@ namespace ElectronicsShopDataBaseImplement.Implements {
|
||||
}
|
||||
|
||||
public PaymeantViewModel? GetElement(PaymeantSearchModel model) {
|
||||
if (model.ProductID.HasValue || model.OrderID.HasValue) {
|
||||
return null;
|
||||
}
|
||||
using var context = new Database();
|
||||
return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model) {
|
||||
if (model.ProductID.HasValue || model.OrderID.HasValue) {
|
||||
return new();
|
||||
}
|
||||
public List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model) {
|
||||
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
|
||||
.Where(x => x.ID == model.ID)
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
.Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<PaymeantViewModel>? GetFullList() {
|
||||
|
@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Clients");
|
||||
b.ToTable("Clients", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
@ -72,7 +72,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("EmployeeID");
|
||||
|
||||
b.ToTable("CostItems");
|
||||
b.ToTable("CostItems", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Employee", b =>
|
||||
@ -97,7 +97,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasKey("ID");
|
||||
|
||||
b.ToTable("Employees");
|
||||
b.ToTable("Employees", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.MessageInfo", b =>
|
||||
@ -127,7 +127,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Messages");
|
||||
b.ToTable("Messages", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Order", b =>
|
||||
@ -151,7 +151,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ClientID");
|
||||
|
||||
b.ToTable("Orders");
|
||||
b.ToTable("Orders", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.OrderProduct", b =>
|
||||
@ -177,7 +177,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("ProductID");
|
||||
|
||||
b.ToTable("OrderProducts");
|
||||
b.ToTable("OrderProducts", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Paymeant", b =>
|
||||
@ -207,7 +207,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("PaymentID");
|
||||
|
||||
b.ToTable("Paymeants");
|
||||
b.ToTable("Paymeants", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.Product", b =>
|
||||
@ -232,7 +232,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
|
||||
b.HasIndex("CostItemID");
|
||||
|
||||
b.ToTable("Products");
|
||||
b.ToTable("Products", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("ElectronicsShopDataBaseImplement.Models.CostItem", b =>
|
||||
|
@ -20,7 +20,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
[ForeignKey("OrderID")]
|
||||
public int OrderID { get; set; }
|
||||
|
||||
[Required]
|
||||
[ForeignKey("ClientID")]
|
||||
public int ClientID { get; set; }
|
||||
|
||||
[Required]
|
||||
|
@ -57,7 +57,7 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[HttpGet]
|
||||
public void CreatePaymeant (PaymeantBindingModel model) {
|
||||
try {
|
||||
_payLogic.CreatePay(model);
|
||||
@ -66,16 +66,5 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
_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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,16 +18,18 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductLogic _product;
|
||||
private readonly IOrderLogic _order;
|
||||
private readonly IPaymeantLogic _paymeant;
|
||||
//private readonly IMessageInfoLogic _message;
|
||||
|
||||
private Dictionary<int, (IProductModel, int)> _productlist;
|
||||
|
||||
public MainController(ILogger<MainController> logger, IProductLogic product,
|
||||
IOrderLogic orderLogic) {
|
||||
IOrderLogic orderLogic, IPaymeantLogic paymeant) {
|
||||
_logger = logger;
|
||||
_product = product;
|
||||
_order = orderLogic;
|
||||
_productlist = new Dictionary<int, (IProductModel, int)>();
|
||||
_paymeant = paymeant;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -220,5 +222,16 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,11 +25,14 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
_productList = new Dictionary<int, (IProductModel, int)>();
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index() {
|
||||
if (APIClient.Client == null) {
|
||||
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]
|
||||
|
Loading…
Reference in New Issue
Block a user