Косметические правки Database
This commit is contained in:
parent
c23317d4b4
commit
cba9740827
@ -12,7 +12,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
{
|
||||
public class AccountStorage : IAccountStorage
|
||||
// Реализация интерфейса хранилища для сущности "Счёт"
|
||||
public class AccountStorage : IAccountStorage
|
||||
{
|
||||
public List<AccountViewModel> GetFullList()
|
||||
{
|
||||
@ -73,8 +74,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
return context.Accounts
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.AccountNumber) && x.AccountNumber == model.AccountNumber) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public AccountViewModel? Insert(AccountBindingModel model)
|
||||
@ -127,6 +127,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public AccountViewModel? Delete(AccountBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.Accounts
|
||||
.Include(x => x.AccountNumber)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
@ -12,7 +12,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
{
|
||||
public class CashWithdrawalStorage : ICashWithdrawalStorage
|
||||
// Реализация интерфейса хранилища для сущности "Снятие наличных"
|
||||
public class CashWithdrawalStorage : ICashWithdrawalStorage
|
||||
{
|
||||
public List<CashWithdrawalViewModel> GetFullList()
|
||||
{
|
||||
@ -29,6 +30,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public List<CashWithdrawalViewModel> GetFilteredList(CashWithdrawalSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var result = context.CashWithdrawals.Include(x => x.Cashier)
|
||||
.Include(x => x.Debiting)
|
||||
.Include(x => x.Account)
|
||||
@ -54,8 +56,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
.Include(x => x.Debiting)
|
||||
.Include(x => x.Account)
|
||||
.FirstOrDefault(x => (!(model.AccountId < 0) && x.AccountId == model.AccountId) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public CashWithdrawalViewModel? Insert(CashWithdrawalBindingModel model)
|
||||
@ -105,6 +106,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public CashWithdrawalViewModel? Delete(CashWithdrawalBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.CashWithdrawals
|
||||
.Include(x => x.AccountId)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
@ -11,7 +11,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
{
|
||||
public class CashierStorage : ICashierStorage
|
||||
// Реализация интерфейса хранилища для сущности "Кассир"
|
||||
public class CashierStorage : ICashierStorage
|
||||
{
|
||||
public List<CashierViewModel> GetFullList()
|
||||
{
|
||||
@ -48,8 +49,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
|
||||
return context.Cashiers
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public CashierViewModel? Insert(CashierBindingModel model)
|
||||
@ -72,6 +72,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public CashierViewModel? Update(CashierBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var cashier = context.Cashiers.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (cashier == null)
|
||||
@ -88,6 +89,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public CashierViewModel? Delete(CashierBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.Cashiers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
|
@ -12,7 +12,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
{
|
||||
public class MoneyTransferStorage : IMoneyTransferStorage
|
||||
// Реализация интерфейса хранилища для сущности "Перевод денег"
|
||||
public class MoneyTransferStorage : IMoneyTransferStorage
|
||||
{
|
||||
public List<MoneyTransferViewModel> GetFullList()
|
||||
{
|
||||
@ -29,6 +30,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public List<MoneyTransferViewModel> GetFilteredList(MoneyTransferSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var result = context.MoneyTransfers.Include(x => x.Cashier)
|
||||
.Include(x => x.AccountPayeer)
|
||||
.Include(x => x.AccountSender)
|
||||
@ -124,6 +126,7 @@ namespace BankDatabaseImplement.Implements.CashierImplements
|
||||
public MoneyTransferViewModel? Delete(MoneyTransferBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.MoneyTransfers
|
||||
.Include(x => x.AccountPayeeId)
|
||||
.Include(x => x.AccountSenderId)
|
||||
|
@ -12,132 +12,134 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
{
|
||||
public class CardStorage : ICardStorage
|
||||
{
|
||||
public CardViewModel? Delete(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var element = context.Cards.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Cards.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Реализация интерфейса хранилища для сущности "Банковская карта"
|
||||
public class CardStorage : ICardStorage
|
||||
{
|
||||
public CardViewModel? GetElement(CardSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Number) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public CardViewModel? GetElement(CardSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Number) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
|
||||
using var context = new BankDatabase();
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Number) && x.Number == model.Number) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Number) && x.Number == model.Number) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public List<CardViewModel> GetFilteredList(CardSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
public List<CardViewModel> GetFilteredList(CardSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
if (!string.IsNullOrEmpty(model.Number))
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.Number.Contains(model.Number))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(model.Number))
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.Number.Contains(model.Number))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.ClientID.HasValue)
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.ClientId == model.ClientID)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (model.ClientID.HasValue)
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.ClientId == model.ClientID)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (model.AccountId.HasValue)
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.AccountId == model.AccountId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
if (model.AccountId.HasValue)
|
||||
{
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Where(x => x.AccountId == model.AccountId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<CardViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
public List<CardViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return context.Cards
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Account)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public CardViewModel? Insert(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
public CardViewModel? Insert(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var newCard = Card.Create(context, model);
|
||||
|
||||
var newCard = Card.Create(context, model);
|
||||
if (newCard == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (newCard == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Cards.Add(newCard);
|
||||
context.SaveChanges();
|
||||
|
||||
context.Cards.Add(newCard);
|
||||
context.SaveChanges();
|
||||
return newCard.GetViewModel;
|
||||
}
|
||||
|
||||
return newCard.GetViewModel;
|
||||
}
|
||||
public CardViewModel? Update(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
public CardViewModel? Update(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var card = context.Cards.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
try
|
||||
{
|
||||
var card = context.Cards.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (card == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (card == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
card.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
|
||||
card.Update(model);
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return card.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return card.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
public CardViewModel? Delete(CardBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var element = context.Cards.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Cards.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,21 +11,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
{
|
||||
public class ClientStorage : IClientStorage
|
||||
// Реализация интерфейса хранилища для сущности "Клиент"
|
||||
public class ClientStorage : IClientStorage
|
||||
{
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password) && !model.Id.HasValue)
|
||||
@ -35,16 +23,14 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
//сработает для поиска почты для отправки файла
|
||||
// Для поиска почты для отправки файла
|
||||
if (model.Id.HasValue && string.IsNullOrEmpty(model.Password))
|
||||
{
|
||||
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
return context.Clients.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.Email) && x.Email == model.Email && !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
return context.Clients.FirstOrDefault(x => (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email
|
||||
&& !string.IsNullOrEmpty(model.Password) && x.Password == model.Password) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||
@ -53,6 +39,7 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
return context.Clients.Where(x => x.Name.Contains(model.Name)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
@ -60,17 +47,21 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
public List<ClientViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ClientViewModel? Insert(ClientBindingModel model)
|
||||
{
|
||||
var newComponent = Client.Create(model);
|
||||
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
context.Clients.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
return newComponent.GetViewModel;
|
||||
@ -79,14 +70,33 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
public ClientViewModel? Update(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var component = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
return component.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,44 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
{
|
||||
public class CreditingStorage : ICreditingStorage
|
||||
// Реализация интерфейса хранилища для сущности "Пополнение карты"
|
||||
public class CreditingStorage : ICreditingStorage
|
||||
{
|
||||
public List<CreditingViewModel> GetFullList()
|
||||
public CreditingViewModel? GetElement(CreditingSearchModel model)
|
||||
{
|
||||
if (model.CardId < 0 && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
return context.Creditings
|
||||
.Include(x => x.Card)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CreditingViewModel> GetFilteredList(CreditingSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var result = context.Creditings.Include(x => x.Card).ToList();
|
||||
|
||||
if (model.CardId.HasValue) result = result.Where(x => x.CardId == model.CardId).ToList();
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
List<int> cards = context.Cards.Where(x => x.ClientId == model.ClientId).Select(x => x.Id).ToList();
|
||||
result = result.Where(x => cards.Contains(x.CardId)).ToList();
|
||||
}
|
||||
|
||||
if (model.DateCrediting.HasValue) result = result.Where(x => x.DateCredit >= model.DateCrediting).ToList();
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<CreditingViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
@ -22,40 +57,7 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
.Include(x => x.Card)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<CreditingViewModel> GetFilteredList(CreditingSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
var result = context.Creditings.Include(x => x.Card).ToList();
|
||||
|
||||
|
||||
if (model.CardId.HasValue) result = result.Where(x => x.CardId == model.CardId).ToList();
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
List<int> cards = context.Cards.Where(x => x.ClientId == model.ClientId).Select(x => x.Id).ToList();
|
||||
result = result.Where(x => cards.Contains(x.CardId)).ToList();
|
||||
}
|
||||
if (model.DateCrediting.HasValue) result = result.Where(x => x.DateCredit >= model.DateCrediting).ToList();
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public CreditingViewModel? GetElement(CreditingSearchModel model)
|
||||
{
|
||||
if (model.CardId < 0 && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
return context.Creditings
|
||||
.Include(x => x.Card)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
public CreditingViewModel? Insert(CreditingBindingModel model)
|
||||
{
|
||||
@ -77,6 +79,7 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
public CreditingViewModel? Update(CreditingBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
@ -107,6 +110,7 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
public CreditingViewModel? Delete(CreditingBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var element = context.Creditings
|
||||
.Include(x => x.CardId)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
@ -12,9 +12,45 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
{
|
||||
public class DebitingStorage : IDebitingStorage
|
||||
// Реализация интерфейса хранилища для сущности "Снятие с карты"
|
||||
public class DebitingStorage : IDebitingStorage
|
||||
{
|
||||
public List<DebitingViewModel> GetFullList()
|
||||
public DebitingViewModel? GetElement(DebitingSearchModel model)
|
||||
{
|
||||
if (model.CardId < 0 && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
return context.Debitings
|
||||
.Include(x => x.Card)
|
||||
.FirstOrDefault(x => (!(model.CardId < 0) && x.CardId == model.CardId) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<DebitingViewModel> GetFilteredList(DebitingSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var result = context.Debitings.Include(x => x.Card).ToList();
|
||||
|
||||
// Для получения всех заявок на стнятие
|
||||
|
||||
if (model.CardId.HasValue) result = result.Where(x => x.CardId == model.CardId).ToList();
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
List<int> cards = context.Cards.Where(x => x.ClientId == model.ClientId).Select(x => x.Id).ToList();
|
||||
result = result.Where(x => cards.Contains(x.CardId)).ToList();
|
||||
}
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<DebitingViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
@ -24,41 +60,6 @@ namespace BankDatabaseImplement.Implements.ClientImplements
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DebitingViewModel> GetFilteredList(DebitingSearchModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
||||
var result = context.Debitings.Include(x => x.Card).ToList();
|
||||
|
||||
//для получения всех заявок на стнятие
|
||||
|
||||
if (model.CardId.HasValue) result = result.Where(x => x.CardId == model.CardId).ToList();
|
||||
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
List<int> cards = context.Cards.Where(x => x.ClientId == model.ClientId).Select(x => x.Id).ToList();
|
||||
result = result.Where(x => cards.Contains(x.CardId)).ToList();
|
||||
}
|
||||
|
||||
return result.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public DebitingViewModel? GetElement(DebitingSearchModel model)
|
||||
{
|
||||
if (model.CardId < 0 && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new BankDatabase();
|
||||
|
||||
return context.Debitings
|
||||
.Include(x => x.Card)
|
||||
.FirstOrDefault(x => (!(model.CardId < 0) && x.CardId == model.CardId) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public DebitingViewModel? Insert(DebitingBindingModel model)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
|
@ -13,8 +13,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.CashierModels
|
||||
{
|
||||
//реализация аккаунта
|
||||
public class Account : IAccountModel
|
||||
// Класс, реализующий интерфейс модели счёта
|
||||
public class Account : IAccountModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -27,7 +27,7 @@ namespace BankDatabaseImplement.Models.CashierModels
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
|
||||
//для передачи ФИО клиента
|
||||
// Для передачи ФИО клиента
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
[Required]
|
||||
@ -39,11 +39,11 @@ namespace BankDatabaseImplement.Models.CashierModels
|
||||
[Required]
|
||||
public StatusAccount StatusAccount { get; set; } = StatusAccount.Открыт;
|
||||
|
||||
//для реализации связи один ко многим со Снятием наличных
|
||||
// Для реализации связи один-ко-многим со Снятием наличных
|
||||
[ForeignKey("AccountId")]
|
||||
public virtual List<CashWithdrawal> CashWithdrawals { get; set; } = new();
|
||||
|
||||
//для реализации связи один ко многим с Переводом денег
|
||||
// Для реализации связи один-ко-многим с Переводом денег
|
||||
[NotMapped]
|
||||
[ForeignKey("AccountSenderId")]
|
||||
public virtual List<MoneyTransfer> MoneyTransferSenders { get; set; } = new();
|
||||
@ -52,7 +52,7 @@ namespace BankDatabaseImplement.Models.CashierModels
|
||||
[ForeignKey("AccountPayeeId")]
|
||||
public virtual List<MoneyTransfer> MoneyTransferPayees { get; set; } = new();
|
||||
|
||||
//для реализации связи один ко многим с Картами
|
||||
// Для реализации связи один-ко-многим с Картами
|
||||
[ForeignKey("AccountId")]
|
||||
public virtual List<Card> Cards { get; set; } = new();
|
||||
|
||||
|
@ -12,26 +12,27 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.CashierModels
|
||||
{
|
||||
public class CashWithdrawal : ICashWithdrawalModel
|
||||
// Класс, реализующий интерфейс модели снятие наличных
|
||||
public class CashWithdrawal : ICashWithdrawalModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int DebitingId { get; set; }
|
||||
|
||||
//для передачи номера заявки
|
||||
// Для передачи номера заявки
|
||||
public virtual Debiting Debiting { get; set; }
|
||||
|
||||
[Required]
|
||||
public int AccountId { get; set; }
|
||||
|
||||
//для передачи номера счета
|
||||
// Для передачи номера счета
|
||||
public virtual Account Account { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CashierId { get; set; }
|
||||
|
||||
//для передачи данных о кассире
|
||||
// Для передачи данных о кассире
|
||||
public virtual Cashier Cashier { get; set; }
|
||||
|
||||
[Required]
|
||||
|
@ -11,7 +11,8 @@ using BankDataModels.Models.Cashier;
|
||||
|
||||
namespace BankDatabaseImplement.Models.CashierModels
|
||||
{
|
||||
public class Cashier : ICashierModel
|
||||
// Класс, реализующий интерфейс модели кассира
|
||||
public class Cashier : ICashierModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.CashierModels
|
||||
{
|
||||
public class MoneyTransfer : IMoneyTransferModel
|
||||
// Класс, реализующий интерфейс модели перевода денег
|
||||
public class MoneyTransfer : IMoneyTransferModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
|
@ -14,7 +14,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.ClientModels
|
||||
{
|
||||
public class Card : ICardModel
|
||||
// Класс, реализующий интерфейс модели банковской карты
|
||||
public class Card : ICardModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -43,10 +44,12 @@ namespace BankDatabaseImplement.Models.ClientModels
|
||||
[Required]
|
||||
public string? ClientSurname { get; set; }
|
||||
|
||||
[ForeignKey("Cardid")]
|
||||
// Для реализации связи один-ко-многим с пополнением карты
|
||||
[ForeignKey("CardId")]
|
||||
public virtual List<Crediting> creditings { get; set; } = new();
|
||||
|
||||
[ForeignKey("Cardid")]
|
||||
// Для реализации связи один-ко-многим со снятием наличных с карты
|
||||
[ForeignKey("CardId")]
|
||||
public virtual List<Debiting> debitings { get; set; } = new();
|
||||
|
||||
public CardViewModel GetViewModel => new()
|
||||
|
@ -11,7 +11,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.ClientModels
|
||||
{
|
||||
public class Client : IClientModel
|
||||
// Класс, реализующий интерфейс модели клиента
|
||||
public class Client : IClientModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -33,7 +34,8 @@ namespace BankDatabaseImplement.Models.ClientModels
|
||||
[Required]
|
||||
public string MobilePhone { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
// Для реализации связи один-ко-многим с банковскими картами
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Card> Cards { get; set; } = new();
|
||||
|
||||
public ClientViewModel GetViewModel => new()
|
||||
|
@ -12,7 +12,8 @@ using BankDatabaseImplement.Models.CashierModels;
|
||||
|
||||
namespace BankDatabaseImplement.Models.ClientModels
|
||||
{
|
||||
public class Crediting : ICreditingModel
|
||||
// Класс, реализующий интерфейс модели пополнения карты
|
||||
public class Crediting : ICreditingModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
@ -29,7 +30,7 @@ namespace BankDatabaseImplement.Models.ClientModels
|
||||
[Required]
|
||||
public DateTime DateCredit { get; set; } = DateTime.Now;
|
||||
|
||||
//для реализации связи один ко многим с переводом денег
|
||||
// Для реализации связи один-ко-многим с переводом денег
|
||||
[ForeignKey("CreditingId")]
|
||||
public virtual List<MoneyTransfer> MoneyTransfers { get; set; } = new();
|
||||
|
||||
|
@ -10,10 +10,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models.ClientModels
|
||||
{
|
||||
public class Debiting : IDebitingModel
|
||||
// Класс, реализующий интерфейс модели снятие с карты
|
||||
public class Debiting : IDebitingModel
|
||||
{
|
||||
//реализация операции на пополнение
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int CardId { get; set; }
|
||||
|
||||
@ -21,6 +22,7 @@ namespace BankDatabaseImplement.Models.ClientModels
|
||||
|
||||
[Required]
|
||||
public double Sum { get; set; }
|
||||
|
||||
[Required]
|
||||
public DateTime DateDebit { get; set; } = DateTime.Now;
|
||||
|
||||
@ -45,7 +47,7 @@ namespace BankDatabaseImplement.Models.ClientModels
|
||||
DateDebit = model.DateDebit,
|
||||
};
|
||||
}
|
||||
//вот тут хз, надо ли обновлять эту операцию, если судить чисто логически, то не надо ОБДУМАТЬ!!!!!!!!
|
||||
// вот тут надо ли обновлять эту операцию..., если судить чисто логически, то не надо ОБДУМАТЬ!!!!!!!! По идее лишним не будет, а может и будет
|
||||
public void Update(DebitingBindingModel model)
|
||||
{
|
||||
DateDebit = model.DateDebit;
|
||||
|
Loading…
Reference in New Issue
Block a user