Доделаны все Storages в BankDataBaseImplement для роли Поставщик.
This commit is contained in:
parent
84a1e0d0fc
commit
930f872ab7
88
Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs
Normal file
88
Bank/BankDatabaseImplement/Implements/BankOperatorStorage.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
public class BankOperatorStorage : IBankOperatorStorage
|
||||
{
|
||||
public BankOperatorViewModel? Delete(BankOperatorBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var element = context.BankOperators.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.BankOperators.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BankOperatorViewModel? GetElement(BankOperatorSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.BankOperators
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<BankOperatorViewModel> GetFilteredList(BankOperatorSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.BankOperators
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BankOperatorViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.BankOperators
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public BankOperatorViewModel? Insert(BankOperatorBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var newBankOperator = BankOperator.Create(model);
|
||||
if (newBankOperator == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.BankOperators.Add(newBankOperator);
|
||||
context.SaveChanges();
|
||||
return newBankOperator.GetViewModel;
|
||||
}
|
||||
|
||||
public BankOperatorViewModel? Update(BankOperatorBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var bankOperator = context.BankOperators.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (bankOperator == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
bankOperator.Update(model);
|
||||
context.SaveChanges();
|
||||
return bankOperator.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
public class CreditProgramStorage : ICreditProgramStorage
|
||||
{
|
||||
public CreditProgramViewModel? Delete(CreditProgramBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var element = context.CreditPrograms.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.CreditPrograms.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public CreditProgramViewModel? GetElement(CreditProgramSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CreditProgramViewModel> GetFilteredList(CreditProgramSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CreditProgramViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CreditProgramViewModel? Insert(CreditProgramBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var newCreditProgram = CreditProgram.Create(context, model);
|
||||
if (newCreditProgram == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.CreditPrograms.Add(newCreditProgram);
|
||||
context.SaveChanges();
|
||||
return newCreditProgram.GetViewModel;
|
||||
}
|
||||
|
||||
public CreditProgramViewModel? Update(CreditProgramBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var creditProgram = context.CreditPrograms.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (creditProgram == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
creditProgram.Update(model);
|
||||
creditProgram.UpdateCurrencies(context, model);
|
||||
context.SaveChanges();
|
||||
return creditProgram.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements
|
||||
{
|
||||
public class CurrencyPurchaseStorage : ICurrencyPurchaseStorage
|
||||
{
|
||||
public CurrencyPurchaseViewModel? Delete(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var currencyPurchase = context.CurrencyPurchases.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (currencyPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
currencyPurchase.Update(model);
|
||||
context.SaveChanges();
|
||||
return currencyPurchase.GetViewModel;
|
||||
}
|
||||
|
||||
public CurrencyPurchaseViewModel? GetElement(CurrencyPurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x=>x.Currency)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CurrencyPurchaseViewModel> GetFilteredList(CurrencyPurchaseSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x=>x.Currency)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CurrencyPurchaseViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.CurrencyPurchases.Include(x => x.BankOperator).Include(x=> x.Currency)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public CurrencyPurchaseViewModel? Insert(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var newCurrencyPurchase = CurrencyPurchase.Create(context, model);
|
||||
if (newCurrencyPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.CurrencyPurchases.Add(newCurrencyPurchase);
|
||||
context.SaveChanges();
|
||||
return newCurrencyPurchase.GetViewModel;
|
||||
}
|
||||
|
||||
public CurrencyPurchaseViewModel? Update(CurrencyPurchaseBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var currencyPurchase = context.CurrencyPurchases.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (currencyPurchase == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
currencyPurchase.Update(model);
|
||||
context.SaveChanges();
|
||||
return currencyPurchase.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user