Готовы модели сущностей роли Заказчик для хранения данных + фикс названия свойства модели Выплаты
This commit is contained in:
parent
9180dfd229
commit
aed455da3f
@ -11,9 +11,9 @@ namespace BankContracts.BindingModels
|
||||
{
|
||||
public DateTime PaymentDate {get;set;} = DateTime.Now.Date;
|
||||
|
||||
public Dictionary<int, IDealModel> Deals { get; set; } = new();
|
||||
public Dictionary<int, IDealModel> DealPayments { get; set; } = new();
|
||||
|
||||
public Dictionary<int, ICurrencyModel> Currencies { get; set; } = new();
|
||||
public Dictionary<int, ICurrencyModel> CurrencyPayments { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ namespace BankContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Дата платы")]
|
||||
public DateTime PaymentDate { get; set; } = DateTime.Now.Date;
|
||||
public Dictionary<int, IDealModel> Deals { get; set; } = new();
|
||||
public Dictionary<int, IDealModel> DealPayments { get; set; } = new();
|
||||
|
||||
public Dictionary<int, ICurrencyModel> Currencies { get; set; } = new();
|
||||
public Dictionary<int, ICurrencyModel> CurrencyPayments { get; set; } = new();
|
||||
[DisplayName("Номер платы")]
|
||||
public int Id { get; set; }
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace BankDataModels.Models
|
||||
public interface IPaymentModel : IId
|
||||
{
|
||||
DateTime PaymentDate { get; }
|
||||
Dictionary<int, IDealModel> Deals { get; }
|
||||
Dictionary<int, ICurrencyModel> Currencies { get; }
|
||||
Dictionary<int, IDealModel> DealPayments { get; }
|
||||
Dictionary<int, ICurrencyModel> CurrencyPayments { get; }
|
||||
}
|
||||
}
|
||||
|
30
Bank/BankDatabaseImplement/BankDatabase.cs
Normal file
30
Bank/BankDatabaseImplement/BankDatabase.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using BankDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.Design;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement
|
||||
{
|
||||
public class BankDatabase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseSqlServer(@"Data Source=localhost\SQLEXPRESS;Initial Catalog=BankDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Operator> Operators { set; get; }
|
||||
public virtual DbSet<Deal> Deals { set; get; }
|
||||
public virtual DbSet<Payment> Payments { set; get; }
|
||||
public virtual DbSet<Transfer> Transfers { set; get; }
|
||||
public virtual DbSet<DealPayment> DealPayments { set; get; }
|
||||
public virtual DbSet<CurrencyPayment> CurrencyPayments { set; get; }
|
||||
|
||||
}
|
||||
}
|
@ -6,4 +6,18 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
|
||||
<ProjectReference Include="..\BankDataModels\BankDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
20
Bank/BankDatabaseImplement/Models/CurrencyPayment.cs
Normal file
20
Bank/BankDatabaseImplement/Models/CurrencyPayment.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
public class CurrencyPayment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int CurrencyId { get; set; }
|
||||
[Required]
|
||||
public int PaymentId { get; set; }
|
||||
public virtual Currency Currency { get; set; } = new();
|
||||
public virtual Payment Payment { get; set; } = new();
|
||||
}
|
||||
}
|
@ -1,12 +1,72 @@
|
||||
using System;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
internal class Deal
|
||||
public class Deal : IDealModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int ClientId { get; set; }
|
||||
[Required]
|
||||
public DateTime DealDate { get; set; } = DateTime.Now;
|
||||
[Required]
|
||||
public int OperatorId { get; set; }
|
||||
public virtual Operator Operator { get; set; } = new();
|
||||
public int? CreditProgramId {get; set; }
|
||||
[ForeignKey("DealId")]
|
||||
public virtual List<DealPayment> DealPayments { get; set; } = new();
|
||||
public static Deal? Create(BankDatabase context, DealBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Deal()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
DealDate = model.DealDate,
|
||||
OperatorId = model.OperatorId,
|
||||
Operator = context.Operators.First(x => x.Id == model.OperatorId)
|
||||
};
|
||||
}
|
||||
public static Deal? Create(BankDatabase context, DealViewModel model)
|
||||
{
|
||||
return new Deal()
|
||||
{
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId,
|
||||
DealDate = model.DealDate,
|
||||
OperatorId = model.OperatorId,
|
||||
Operator = context.Operators.First(x => x.Id == model.OperatorId)
|
||||
};
|
||||
}
|
||||
public void Update(DealBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ClientId = model.ClientId;
|
||||
if (model.CreditProgramId.HasValue) CreditProgramId = CreditProgramId;
|
||||
}
|
||||
public DealViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ClientId = ClientId,
|
||||
CreditProgramId = CreditProgramId,
|
||||
DealDate = DealDate,
|
||||
OperatorId = OperatorId,
|
||||
OperatorName = Operator.LastName + " " + Operator.FirstName + " " + Operator.MiddleName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
20
Bank/BankDatabaseImplement/Models/DealPayment.cs
Normal file
20
Bank/BankDatabaseImplement/Models/DealPayment.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
public class DealPayment
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public int DealId { get; set; }
|
||||
[Required]
|
||||
public int PaymentId { get; set; }
|
||||
public virtual Deal Deal { get; set; } = new();
|
||||
public virtual Payment Payment { get; set; } = new();
|
||||
}
|
||||
}
|
58
Bank/BankDatabaseImplement/Models/Operator.cs
Normal file
58
Bank/BankDatabaseImplement/Models/Operator.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
public class Operator : IOperatorModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Login {get; set;} = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
public string? MiddleName { get; set; }
|
||||
|
||||
public static Operator? Create(BankDatabase context, OperatorViewModel model)
|
||||
{
|
||||
return new Operator()
|
||||
{
|
||||
Id = model.Id,
|
||||
Login = model.Login,
|
||||
Password = model.Password,
|
||||
LastName = model.LastName,
|
||||
FirstName = model.FirstName,
|
||||
MiddleName = model.MiddleName,
|
||||
};
|
||||
}
|
||||
public void Update(OperatorBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Password = model.Password;
|
||||
LastName = model.LastName;
|
||||
FirstName = model.FirstName;
|
||||
MiddleName = model.MiddleName;
|
||||
}
|
||||
public OperatorViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Login = Login,
|
||||
Password = Password,
|
||||
LastName = LastName,
|
||||
FirstName = FirstName,
|
||||
MiddleName = MiddleName,
|
||||
};
|
||||
}
|
||||
}
|
129
Bank/BankDatabaseImplement/Models/Payment.cs
Normal file
129
Bank/BankDatabaseImplement/Models/Payment.cs
Normal file
@ -0,0 +1,129 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using Microsoft.Identity.Client;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
public class Payment : IPaymentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[Required]
|
||||
public DateTime PaymentDate { get; set; } = DateTime.Now;
|
||||
private Dictionary<int, IDealModel>? _dealPayments = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, IDealModel> DealPayments {
|
||||
get
|
||||
{
|
||||
if (_dealPayments == null)
|
||||
{
|
||||
_dealPayments = Deals.ToDictionary(recDP => recDP.DealId, recDP => recDP.Deal as IDealModel);
|
||||
}
|
||||
return _dealPayments;
|
||||
}
|
||||
}
|
||||
[ForeignKey("PaymentId")]
|
||||
public virtual List<DealPayment> Deals { get; set; } = new();
|
||||
private Dictionary<int, ICurrencyModel>? _currencyPayments = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, ICurrencyModel> CurrencyPayments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currencyPayments == null)
|
||||
{
|
||||
_currencyPayments = Currencies.ToDictionary(recCP => recCP.CurrencyId, recCP => recCP.Currency as ICurrencyModel);
|
||||
}
|
||||
return _currencyPayments;
|
||||
}
|
||||
}
|
||||
public virtual List<CurrencyPayment> Currencies { get; set; } = new();
|
||||
|
||||
public static Payment? Create(BankDatabase context, PaymentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Payment()
|
||||
{
|
||||
Id = model.Id,
|
||||
PaymentDate = model.PaymentDate,
|
||||
Deals = model.DealPayments.Select(x => new DealPayment
|
||||
{
|
||||
Deal = context.Deals.First(y => y.Id == x.Key)
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
public void Update(PaymentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
PaymentDate = model.PaymentDate;
|
||||
}
|
||||
public PaymentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
PaymentDate = PaymentDate,
|
||||
DealPayments = DealPayments,
|
||||
CurrencyPayments = CurrencyPayments,
|
||||
};
|
||||
public void UpdateDeals(BankDatabase context, PaymentBindingModel model)
|
||||
{
|
||||
var dealPayments = context.DealPayments.Where(rec => rec.PaymentId == model.Id).ToList();
|
||||
if (dealPayments != null && dealPayments.Count > 0)
|
||||
{
|
||||
context.DealPayments.RemoveRange(dealPayments.Where(rec => !model.DealPayments.ContainsKey(rec.DealId)));
|
||||
context.SaveChanges();
|
||||
var payment = context.Payments.First(x => x.Id == Id);
|
||||
foreach (var updateIngredient in dealPayments)
|
||||
{
|
||||
model.DealPayments.Remove(updateIngredient.DealId);
|
||||
}
|
||||
foreach (var dp in model.DealPayments)
|
||||
{
|
||||
context.DealPayments.Add(new DealPayment
|
||||
{
|
||||
Payment = payment,
|
||||
Deal = context.Deals.First(x => x.Id == dp.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_dealPayments = null;
|
||||
}
|
||||
}
|
||||
public void UpdateCurrencies(BankDatabase context, PaymentBindingModel model)
|
||||
{
|
||||
var currencyPayments = context.CurrencyPayments.Where(rec => rec.PaymentId == model.Id).ToList();
|
||||
if (currencyPayments != null && currencyPayments.Count > 0)
|
||||
{
|
||||
context.CurrencyPayments.RemoveRange(currencyPayments.Where(rec => !model.CurrencyPayments.ContainsKey(rec.CurrencyId)));
|
||||
context.SaveChanges();
|
||||
var payment = context.Payments.First(x => x.Id == Id);
|
||||
foreach (var updateIngredient in currencyPayments)
|
||||
{
|
||||
model.CurrencyPayments.Remove(updateIngredient.CurrencyId);
|
||||
}
|
||||
foreach (var cp in model.CurrencyPayments)
|
||||
{
|
||||
context.CurrencyPayments.Add(new CurrencyPayment
|
||||
{
|
||||
Payment = payment,
|
||||
Currency = context.Currencies.First(x => x.Id == cp.Key),
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_currencyPayments = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
65
Bank/BankDatabaseImplement/Models/Transfer.cs
Normal file
65
Bank/BankDatabaseImplement/Models/Transfer.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.ViewModels;
|
||||
using BankDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankDatabaseImplement.Models
|
||||
{
|
||||
public class Transfer : ITransferModel
|
||||
{
|
||||
public int Id {get; set;}
|
||||
[Required]
|
||||
public float Amount { get; set; }
|
||||
[Required]
|
||||
public DateTime TransferDateTime { get; set; } = DateTime.Now;
|
||||
[Required]
|
||||
public int PaymentId { get; set; }
|
||||
public virtual Payment Payment { get; set; } = new();
|
||||
public static Transfer? Create(BankDatabase context, TransferBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Transfer()
|
||||
{
|
||||
Id = model.Id,
|
||||
Amount = model.Amount,
|
||||
TransferDateTime = model.TransferDateTime,
|
||||
PaymentId = model.PaymentId,
|
||||
Payment = context.Payments.First(x => x.Id == model.PaymentId)
|
||||
};
|
||||
}
|
||||
public static Transfer? Create(BankDatabase context, TransferViewModel model)
|
||||
{
|
||||
return new Transfer()
|
||||
{
|
||||
Id = model.Id,
|
||||
Amount = model.Amount,
|
||||
TransferDateTime = model.TransferDateTime,
|
||||
PaymentId = model.PaymentId,
|
||||
Payment = context.Payments.First(x => x.Id == model.PaymentId)
|
||||
};
|
||||
}
|
||||
public void Update(TransferBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Amount = model.Amount;
|
||||
}
|
||||
public TransferViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
TransferDateTime = TransferDateTime,
|
||||
Amount = Amount,
|
||||
PaymentId = PaymentId
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user