set paymeant

This commit is contained in:
Илья Федотов 2024-05-26 18:12:25 +04:00
parent 1a56a5f1d4
commit e07a12bf92
12 changed files with 106 additions and 68 deletions

View File

@ -3,22 +3,23 @@ using ElectronicsShopContracts.BusinessLogicContracts;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.StorageContracts;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using Microsoft.Extensions.Logging;
namespace ElectronicsShopBusinessLogic.BusinessLogic
{
public class PaymentLogic : IPaymentLogic
public class PaymeantLogic : IPaymeantLogic
{
private readonly ILogger _logger;
private readonly IPaymentStorage _storage;
private readonly IPaymeantStorage _storage;
public PaymentLogic(ILogger<PaymentLogic> logger, IPaymentStorage storage) {
public PaymeantLogic(ILogger<PaymeantLogic> logger, IPaymeantStorage storage) {
_logger = logger;
_storage = storage;
}
public bool CreatePay(PaymentBindingModel model)
public bool CreatePay(PaymeantBindingModel model)
{
CheckModel(model);
if (_storage.Insert(model) == null)
@ -29,7 +30,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return true;
}
public PaymentViewModel? ReadElement(PaymentSearchModel model)
public PaymeantViewModel? ReadElement(PaymeantSearchModel model)
{
if (model == null)
{
@ -46,7 +47,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return element;
}
public List<PaymentViewModel>? ReadList(PaymentSearchModel? model)
public List<PaymeantViewModel>? ReadList(PaymeantSearchModel? model)
{
_logger.LogInformation($"ReadList. ClientID:{model?.ID}");
var list = model == null ? _storage.GetFullList() : _storage.GetFillteredList(model); ;
@ -59,8 +60,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
return null;
}
private void CheckModel(PaymentBindingModel model, bool withParams = true)
private void CheckModel(PaymeantBindingModel model, bool withParams = true)
{
if (!withParams)
{
@ -73,5 +74,23 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
_logger.LogInformation($"Payment. ID:{model.ID}.ProductID:{model.ProductID}.Sum:{model.SumPayment}.OrderID:{model.OrderID}" +
$".PayOption{model.PayOption}");
}
}
public bool SetFullPayment(PaymeantBindingModel model) {
throw new NotImplementedException();
}
public bool SetPartialPayemnt(PaymeantBindingModel model) {
throw new NotImplementedException();
}
public bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption) {
CheckModel(model, false);
model.PayOption = paymeantOption;
if (_storage.UpdatePay == null) {
_logger.LogWarning("update operation failed");
return false;
}
return true;
}
}
}

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopContracts.BindingModels
{
public class PaymentBindingModel : IPaymentModel
public class PaymeantBindingModel : IPaymentModel
{
public int ID { get; set; }

View File

@ -0,0 +1,25 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IPaymeantLogic
{
List<PaymeantViewModel>? ReadList(PaymeantSearchModel model);
PaymeantViewModel? ReadElement(PaymeantSearchModel model);
bool CreatePay(PaymeantBindingModel model);
bool SetStatus(PaymeantBindingModel model, PaymeantOption paymeantOption);
bool SetFullPayment(PaymeantBindingModel model);
bool SetPartialPayemnt(PaymeantBindingModel model);
}
}

View File

@ -1,19 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.BusinessLogicContracts
{
public interface IPaymentLogic
{
List<PaymentViewModel>? ReadList(PaymentSearchModel model);
PaymentViewModel? ReadElement(PaymentSearchModel model);
bool CreatePay(PaymentBindingModel model);
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopContracts.SearchModels
{
public class PaymentSearchModel
public class PaymeantSearchModel
{
public int? ID { get; set; }
public int? ProductID { get; set; }

View File

@ -0,0 +1,21 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface IPaymeantStorage
{
List<PaymeantViewModel>? GetFullList();
List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model);
PaymeantViewModel? GetElement(PaymeantSearchModel model);
PaymeantViewModel? Insert(PaymeantBindingModel model);
PaymeantViewModel? UpdatePay(PaymeantBindingModel model);
}
}

View File

@ -1,20 +0,0 @@
using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.SearchModels;
using ElectronicsShopContracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopContracts.StorageContracts
{
public interface IPaymentStorage
{
List<PaymentViewModel>? GetFullList();
List<PaymentViewModel>? GetFillteredList(PaymentSearchModel model);
PaymentViewModel? GetElement(PaymentSearchModel model);
PaymentViewModel? Insert(PaymentBindingModel model);
}
}

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopContracts.ViewModels
{
public class PaymentViewModel : IPaymentModel {
public class PaymeantViewModel : IPaymentModel {
public int ID { get; set; }
public int ProductID { get; set; }

View File

@ -20,6 +20,6 @@ namespace ElectronicsShopDataBaseImplement
public virtual DbSet<OrderProduct> OrderProducts { set; get; }
public virtual DbSet<Employee> Employees { set; get; }
public virtual DbSet<CostItem> CostItems { set; get; }
public virtual DbSet<Payment> Payments { get; set; }
public virtual DbSet<Paymeant> Paymeants { get; set; }
}
}

View File

@ -7,43 +7,55 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Implements {
public class PaymentStorage : IPaymentStorage {
public PaymentViewModel? Insert(PaymentBindingModel model) {
var newPayment = Payment.Create(model);
public class PaymeantStorage : IPaymeantStorage {
public PaymeantViewModel? Insert(PaymeantBindingModel model) {
var newPayment = Paymeant.Create(model);
if (newPayment == null) {
return null;
}
using var context = new Database();
context.Payments.Add(newPayment);
context.Paymeants.Add(newPayment);
context.SaveChanges();
return newPayment.GetViewModel;
}
public PaymentViewModel? GetElement(PaymentSearchModel model) {
public PaymeantViewModel? UpdatePay(PaymeantBindingModel model) {
using var context = new Database();
var paymeant = context.Paymeants.FirstOrDefault(x => x.ID == model.ID);
if (paymeant == null) {
return null;
}
paymeant.Update(model);
context.SaveChanges();
return paymeant.GetViewModel;
}
public PaymeantViewModel? GetElement(PaymeantSearchModel model) {
if (model.ProductID.HasValue || model.OrderID.HasValue) {
return null;
}
using var context = new Database();
return context.Payments.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<PaymentViewModel>? GetFillteredList(PaymentSearchModel model) {
public List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model) {
if (model.ProductID.HasValue || model.OrderID.HasValue) {
return new();
}
using var context = new Database();
return context.Payments
return context.Paymeants
.Where(x => x.ID == model.ID)
.Select(x => x.GetViewModel).ToList();
}
public List<PaymentViewModel>? GetFullList() {
public List<PaymeantViewModel>? GetFullList() {
using var context = new Database();
return context.Payments.Select(x => x.GetViewModel).ToList();
return context.Paymeants.Select(x => x.GetViewModel).ToList();
}
}
}

View File

@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Models
public virtual List<OrderProduct> Products { get; set; } = new();
[ForeignKey("PaymentID")]
public virtual List<Payment> Payments { get; set; } = new();
public virtual List<Paymeant> Payments { get; set; } = new();
public static Order? Create(Database context ,OrderBindingModel? model)
{

View File

@ -13,7 +13,7 @@ using System.Threading.Tasks;
namespace ElectronicsShopDataBaseImplement.Models
{
public class Payment : IPaymentModel
public class Paymeant : IPaymentModel
{
public int ID { get; set; }
@ -29,13 +29,13 @@ namespace ElectronicsShopDataBaseImplement.Models
[Required]
public PaymeantOption PayOption { get; set; } = PaymeantOption.Неоплачено;
public static Payment? Create(PaymentBindingModel? model)
public static Paymeant? Create(PaymeantBindingModel? model)
{
if (model == null)
{
return null;
}
return new Payment()
return new Paymeant()
{
ID = model.ID,
ProductID = model.ProductID,
@ -44,7 +44,7 @@ namespace ElectronicsShopDataBaseImplement.Models
PayOption = model.PayOption,
};
}
public void Update(PaymentBindingModel? model)
public void Update(PaymeantBindingModel? model)
{
if (model == null)
{
@ -56,7 +56,7 @@ namespace ElectronicsShopDataBaseImplement.Models
PayOption = model.PayOption;
}
public PaymentViewModel GetViewModel => new()
public PaymeantViewModel GetViewModel => new()
{
ID = ID,
ProductID = ProductID,