56 lines
1.7 KiB
C#
56 lines
1.7 KiB
C#
using ElectronicsShopContracts.BindingModels;
|
|
using ElectronicsShopContracts.SearchModels;
|
|
using ElectronicsShopContracts.StorageContracts;
|
|
using ElectronicsShopContracts.ViewModels;
|
|
using ElectronicsShopDataBaseImplement.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
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 PaymeantStorage : IPaymeantStorage {
|
|
public PaymeantViewModel? Insert(PaymeantBindingModel model) {
|
|
var newPayment = Paymeant.Create(model);
|
|
if (newPayment == null) {
|
|
return null;
|
|
}
|
|
using var context = new Database();
|
|
context.Paymeants.Add(newPayment);
|
|
context.SaveChanges();
|
|
return newPayment.GetViewModel;
|
|
}
|
|
|
|
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) {
|
|
using var context = new Database();
|
|
return context.Paymeants.FirstOrDefault(x => (model.ID.HasValue && x.ID == model.ID))?.GetViewModel;
|
|
}
|
|
|
|
public List<PaymeantViewModel> GetFillteredList(PaymeantSearchModel model) {
|
|
using var context = new Database();
|
|
return context.Paymeants
|
|
.Where(x => x.ClientID == model.ClientID).Select(x => x.GetViewModel).ToList();
|
|
}
|
|
|
|
public List<PaymeantViewModel>? GetFullList() {
|
|
using var context = new Database();
|
|
return context.Paymeants.Select(x => x.GetViewModel).ToList();
|
|
}
|
|
}
|
|
}
|