2024-05-26 17:47:24 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.SearchModels;
|
|
|
|
|
using ElectronicsShopContracts.StorageContracts;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
|
|
|
|
using ElectronicsShopDataBaseImplement.Models;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Security;
|
2024-05-26 18:12:25 +04:00
|
|
|
|
using System.Numerics;
|
2024-05-26 17:47:24 +04:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopDataBaseImplement.Implements {
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public class PaymeantStorage : IPaymeantStorage {
|
|
|
|
|
public PaymeantViewModel? Insert(PaymeantBindingModel model) {
|
|
|
|
|
var newPayment = Paymeant.Create(model);
|
2024-05-26 17:47:24 +04:00
|
|
|
|
if (newPayment == null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new Database();
|
2024-05-26 18:12:25 +04:00
|
|
|
|
context.Paymeants.Add(newPayment);
|
2024-05-26 17:47:24 +04:00
|
|
|
|
context.SaveChanges();
|
|
|
|
|
return newPayment.GetViewModel;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
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) {
|
2024-05-26 17:47:24 +04:00
|
|
|
|
if (model.ProductID.HasValue || model.OrderID.HasValue) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
using var context = new Database();
|
2024-05-26 18:12:25 +04:00
|
|
|
|
return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
2024-05-26 17:47:24 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public List<PaymeantViewModel>? GetFillteredList(PaymeantSearchModel model) {
|
2024-05-26 17:47:24 +04:00
|
|
|
|
if (model.ProductID.HasValue || model.OrderID.HasValue) {
|
|
|
|
|
return new();
|
|
|
|
|
}
|
|
|
|
|
using var context = new Database();
|
2024-05-26 18:12:25 +04:00
|
|
|
|
return context.Paymeants
|
2024-05-26 17:47:24 +04:00
|
|
|
|
.Where(x => x.ID == model.ID)
|
|
|
|
|
.Select(x => x.GetViewModel).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-26 18:12:25 +04:00
|
|
|
|
public List<PaymeantViewModel>? GetFullList() {
|
2024-05-26 17:47:24 +04:00
|
|
|
|
using var context = new Database();
|
2024-05-26 18:12:25 +04:00
|
|
|
|
return context.Paymeants.Select(x => x.GetViewModel).ToList();
|
2024-05-26 17:47:24 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|