50 lines
1.5 KiB
C#
50 lines
1.5 KiB
C#
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;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ElectronicsShopDataBaseImplement.Implements {
|
|
public class PaymentStorage : IPaymentStorage {
|
|
public PaymentViewModel? Insert(PaymentBindingModel model) {
|
|
var newPayment = Payment.Create(model);
|
|
if (newPayment == null) {
|
|
return null;
|
|
}
|
|
using var context = new Database();
|
|
context.Payments.Add(newPayment);
|
|
context.SaveChanges();
|
|
return newPayment.GetViewModel;
|
|
}
|
|
|
|
public PaymentViewModel? GetElement(PaymentSearchModel 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;
|
|
}
|
|
|
|
public List<PaymentViewModel>? GetFillteredList(PaymentSearchModel model) {
|
|
if (model.ProductID.HasValue || model.OrderID.HasValue) {
|
|
return new();
|
|
}
|
|
using var context = new Database();
|
|
return context.Payments
|
|
.Where(x => x.ID == model.ID)
|
|
.Select(x => x.GetViewModel).ToList();
|
|
}
|
|
|
|
public List<PaymentViewModel>? GetFullList() {
|
|
using var context = new Database();
|
|
return context.Payments.Select(x => x.GetViewModel).ToList();
|
|
}
|
|
}
|
|
}
|