Фикс: привязка BankOperator к сущностям CreditProgram и Currency. Добавление BankOperatorId в SearchModel CurrencyPurchase/
This commit is contained in:
parent
930f872ab7
commit
22090fb93d
@ -16,5 +16,6 @@ namespace BankContracts.BindingModels
|
||||
public Dictionary<int, ICurrencyModel> CreditProgramCurrencies { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,5 +11,6 @@ namespace BankContracts.BindingModels
|
||||
{
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public int Id { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace BankContracts.SearchModels
|
||||
public class CreditProgramSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? BankOperatorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace BankContracts.SearchModels
|
||||
public class CurrencyPurchaseSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? BankOperatorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace BankContracts.SearchModels
|
||||
public class CurrencySearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public int? BankOperatorId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,14 @@ namespace BankContracts.ViewModels
|
||||
public class CreditProgramViewModel : ICreditProgramModel
|
||||
{
|
||||
[DisplayName("Название кредитной программы")]
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Процент кредитования")]
|
||||
public float Percent { get; set; }
|
||||
public Dictionary<int, ICurrencyModel> CreditProgramCurrencies { get; set; } = new();
|
||||
[DisplayName("Номер программы")]
|
||||
public int Id { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
[DisplayName("ФИО оператора")]
|
||||
public string BankOperatorFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -16,11 +16,12 @@ namespace BankContracts.ViewModels
|
||||
public DateTime PurchaseDate { get; set; } = DateTime.Now.Date;
|
||||
public int BankOperatorId { get; set; }
|
||||
[DisplayName("ФИО оператора")]
|
||||
public string BankOperatorName { get; set; }
|
||||
public string BankOperatorName { get; set; } = string.Empty;
|
||||
public int CurrencyId { get; set; }
|
||||
[DisplayName("Название валюты")]
|
||||
public string CurrencyName { get; set; }
|
||||
public string CurrencyName { get; set; } = string.Empty;
|
||||
[DisplayName("Номер покупки")]
|
||||
public int Id { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -11,8 +11,11 @@ namespace BankContracts.ViewModels
|
||||
public class CurrencyViewModel : ICurrencyModel
|
||||
{
|
||||
[DisplayName("Название валюты")]
|
||||
public string Name { get; set; } = String.Empty;
|
||||
public string Name { get; set; } = string.Empty;
|
||||
[DisplayName("Номер валюты")]
|
||||
public int Id { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
[DisplayName("ФИО оператора")]
|
||||
public string BankOperatorName { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ namespace BankDataModels.Models
|
||||
{
|
||||
string Name { get;}
|
||||
float Percent { get;}
|
||||
int BankOperatorId { get;}
|
||||
Dictionary<int, ICurrencyModel> CreditProgramCurrencies { get; }
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,6 @@ namespace BankDataModels.Models
|
||||
public interface ICurrencyModel : IId
|
||||
{
|
||||
string Name { get; }
|
||||
int BankOperatorId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -33,28 +34,39 @@ namespace BankDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
return context.CreditPrograms.Include(x => x.BankOperator)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CreditProgramViewModel> GetFilteredList(CreditProgramSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.BankOperatorId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.BankOperatorId.HasValue)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms.Include(x => x.BankOperator)
|
||||
.Where(x => x.BankOperatorId == model.BankOperatorId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms.Include(x => x.BankOperator)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<CreditProgramViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.CreditPrograms
|
||||
return context.CreditPrograms.Include(x => x.BankOperator)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ using BankContracts.SearchModels;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -33,28 +34,39 @@ namespace BankDatabaseImplement.Implements
|
||||
return null;
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.Currencies
|
||||
return context.Currencies.Include(x => x.BankOperator)
|
||||
.FirstOrDefault(x => x.Id == model.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<CurrencyViewModel> GetFilteredList(CurrencySearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
if (!model.Id.HasValue && !model.BankOperatorId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new BankDatabase();
|
||||
return context.Currencies
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.BankOperatorId.HasValue)
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Currencies.Include(x => x.BankOperator)
|
||||
.Where(x => x.BankOperatorId == model.BankOperatorId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Currencies.Include(x => x.BankOperator)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public List<CurrencyViewModel> GetFullList()
|
||||
{
|
||||
using var context = new BankDatabase();
|
||||
return context.Currencies
|
||||
return context.Currencies.Include(x => x.BankOperator)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ namespace BankDatabaseImplement.Models
|
||||
public float Percent { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
public virtual BankOperator BankOperator { get; set; } = new();
|
||||
|
||||
private Dictionary<int, ICurrencyModel>? _creditProgramCurrencies = null;
|
||||
[NotMapped]
|
||||
@ -49,7 +51,9 @@ namespace BankDatabaseImplement.Models
|
||||
Currencies = model.CreditProgramCurrencies.Select(x => new CreditProgramCurrency
|
||||
{
|
||||
Currency = context.Currencies.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
}).ToList(),
|
||||
BankOperatorId = model.BankOperatorId,
|
||||
BankOperator = context.BankOperators.First(x => x.Id == model.BankOperatorId),
|
||||
};
|
||||
}
|
||||
public void Update(CreditProgramBindingModel? model)
|
||||
@ -73,7 +77,7 @@ namespace BankDatabaseImplement.Models
|
||||
var creditProgramsCurrencies = context.CreditProgramCurrencies.Where(rec => rec.CreditProgramId == model.Id).ToList();
|
||||
if (creditProgramsCurrencies != null && creditProgramsCurrencies.Count > 0)
|
||||
{
|
||||
context.CreditProgramCurrencies.RemoveRange(creditProgramsCurrencies.Where(rec => !model.CreditProgramCurrencies.ContainsKey(rec.DealId)));
|
||||
context.CreditProgramCurrencies.RemoveRange(creditProgramsCurrencies.Where(rec => !model.CreditProgramCurrencies.ContainsKey(rec.CreditProgramId)));
|
||||
context.SaveChanges();
|
||||
var creditProgram = context.CreditPrograms.First(x => x.Id == Id);
|
||||
foreach (var updateCurrency in creditProgramsCurrencies)
|
||||
|
@ -16,6 +16,8 @@ namespace BankDatabaseImplement.Models
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public string Name { get; set; }
|
||||
public int BankOperatorId { get; set; }
|
||||
public virtual BankOperator BankOperator { get; set; } = new();
|
||||
public static Currency? Create(BankDatabase context, CurrencyBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -26,7 +28,10 @@ namespace BankDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
BankOperatorId = model.BankOperatorId,
|
||||
BankOperator = context.BankOperators.First(x => x.Id == model.BankOperatorId),
|
||||
};
|
||||
|
||||
}
|
||||
public static Currency? Create(BankDatabase context, CurrencyViewModel model)
|
||||
{
|
||||
@ -34,6 +39,8 @@ namespace BankDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
BankOperatorId = model.BankOperatorId,
|
||||
BankOperator = context.BankOperators.First(x => x.Id == model.BankOperatorId),
|
||||
};
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user