84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using LawFirmContracts.BindingModels;
|
|||
|
using LawFirmContracts.Models;
|
|||
|
using LawFirmContracts.SearchModels;
|
|||
|
using LawFirmContracts.StorageContracts;
|
|||
|
using LawFirmContracts.ViewModels;
|
|||
|
using LawFirmDatabase.Models;
|
|||
|
|
|||
|
namespace LawFirmDatabase.Implements
|
|||
|
{
|
|||
|
public class PaymentStorage : IPaymentStorage
|
|||
|
{
|
|||
|
public List<PaymentViewModel> GetFullList()
|
|||
|
{
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
return context.Payments
|
|||
|
.Select(x => x.GetViewModel)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public List<PaymentViewModel> GetFilteredList(PaymentSearchModel model)
|
|||
|
{
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
return context.Payments
|
|||
|
.Where(x => x.Id == model.Id)
|
|||
|
.Select(x => x.GetViewModel)
|
|||
|
.ToList();
|
|||
|
}
|
|||
|
public PaymentViewModel? GetElement(PaymentSearchModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
if (model.Id.HasValue)
|
|||
|
{
|
|||
|
return context.Payments
|
|||
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
public PaymentViewModel? Insert(PaymentBindingModel model)
|
|||
|
{
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
var newPayment = Payment.Create(context, model);
|
|||
|
if (newPayment != null)
|
|||
|
{
|
|||
|
context.Payments.Add(newPayment);
|
|||
|
context.SaveChanges();
|
|||
|
return newPayment.GetViewModel;
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
public PaymentViewModel? Update(PaymentBindingModel model)
|
|||
|
{
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
var payment = context.Payments.FirstOrDefault(x => x.Id == model.Id);
|
|||
|
if (payment == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
payment.Update(context, model);
|
|||
|
context.SaveChanges();
|
|||
|
return payment.GetViewModel;
|
|||
|
}
|
|||
|
public PaymentViewModel? Delete(PaymentBindingModel model)
|
|||
|
{
|
|||
|
using var context = new LawFirmDBContext();
|
|||
|
var payment = context.Payments.FirstOrDefault(x => x.Id == model.Id);
|
|||
|
if (payment == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
context.Payments.Remove(payment);
|
|||
|
context.SaveChanges();
|
|||
|
return payment.GetViewModel;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|