Частично сделала хранилище

This commit is contained in:
Artyom_Yashin 2024-04-26 14:01:41 +04:00
parent 0e84426c99
commit 5c39e8da26
7 changed files with 259 additions and 1 deletions

View File

@ -5,7 +5,9 @@ VisualStudioVersion = 17.9.34723.18
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankDataModels", "BankDataModels\BankDataModels.csproj", "{B74F0734-6D5B-41D5-AF9B-23CF7535C52F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankContracts", "BankContracts\BankContracts.csproj", "{59CDEA88-47C6-434D-84C6-40390E267858}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BankContracts", "BankContracts\BankContracts.csproj", "{59CDEA88-47C6-434D-84C6-40390E267858}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BankDatabaseImplement", "BankDatabaseImplement\BankDatabaseImplement.csproj", "{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +23,10 @@ Global
{59CDEA88-47C6-434D-84C6-40390E267858}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59CDEA88-47C6-434D-84C6-40390E267858}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59CDEA88-47C6-434D-84C6-40390E267858}.Release|Any CPU.Build.0 = Release|Any CPU
{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E038E32E-3601-4A3C-BB3D-301F9AE9B8E7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
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);
}
}
}

View File

@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BankContracts\BankContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,78 @@
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
{
public class Card : ICardModel
{
public int Id { get; set; }
[Required]
public string Number { get; set; } = string.Empty;
[Required]
public string Cvv { get; set; } = string.Empty;
[Required]
public string Pin { get; set; } = string.Empty;
[Required]
public DateOnly ReleaseDate { get; set; }
[Required]
public DateOnly ExpirationDate { get; set; }
[Required]
public int ClientId { get; set; }
[Required]
public int? AccountId { get; set; } = null;
[ForeignKey("CardId")]
public virtual List<CardRequest> CardRequests { get; set; } = new();
[ForeignKey("SenderCardId")]
public virtual List<Operation> SenderOperations { get; set; } = new();
[ForeignKey("RecipientCardId")]
public virtual List<Operation> RecipientOperations { get; set; } = new();
public static Card? Create(CardBindingModel model)
{
if (model == null) return null;
return new Card
{
Id = model.Id,
Number = model.Number,
Cvv = model.Cvv,
Pin = model.Pin,
ReleaseDate = model.ReleaseDate,
ExpirationDate = model.ExpirationDate,
ClientId = model.ClientId,
AccountId = model.AccountId,
};
}
public void Update(CardBindingModel model)
{
if (model == null) return;
Number = model.Number;
Cvv = model.Cvv;
Pin = model.Pin;
ReleaseDate = model.ReleaseDate;
ExpirationDate = model.ExpirationDate;
ClientId = model.ClientId;
AccountId = model.AccountId;
}
public CardViewModel GetViewModel => new()
{
Id = Id,
Number = Number,
Cvv = Cvv,
Pin = Pin,
ReleaseDate = ReleaseDate,
ExpirationDate = ExpirationDate,
ClientId = ClientId,
AccountId = AccountId,
};
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BankDatabaseImplement.Models
{
public class CardRequest
{
}
}

View File

@ -0,0 +1,63 @@
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
{
public class Client : IClientModel
{
public int Id { get; set; }
[Required]
public string Fio { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty;
[ForeignKey("ClientId")]
public virtual List<Card> Cards { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)
return null;
return new Client
{
Id = model.Id,
Fio = model.Fio,
Email = model.Email,
Password = model.Password,
};
}
public static Client Create(ClientViewModel model)
{
return new Client()
{
Id = model.Id,
Fio = model.Fio,
Email = model.Email,
Password = model.Password,
};
}
public void Update(ClientBindingModel model)
{
if (model == null) return;
Fio = model.Fio;
Email = model.Email;
Password = model.Password;
}
public ClientViewModel GetViewModel => new()
{
Id = Id,
Fio = Fio,
Email = Email,
Password = Password,
};
}
}

View File

@ -0,0 +1,56 @@
using Azure;
using BankContracts.BindingModels;
using BankContracts.ViewModels;
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 Operation
{
public int Id { get; set; }
[Required]
public int Sum { get; set; }
[Required]
public DateTime OperationTime { get; set; }
[Required]
public int? SenderCardId { get; set; } = null;
[Required]
public int RecipientCardId { get; set; }
public static Operation? Create(OperationBindingModel model)
{
if (model == null) return null;
return new Operation
{
Id = model.Id,
Sum = model.Sum,
OperationTime = model.OperationTime,
SenderCardId = model.SenderCardId,
RecipientCardId = model.RecipientCardId,
};
}
public void Update(OperationBindingModel model)
{
if (model == null) return;
Sum = model.Sum;
OperationTime = model.OperationTime;
SenderCardId = model.SenderCardId;
RecipientCardId = model.RecipientCardId;
}
public OperationViewModel GetViewModel => new()
{
Id = Id,
Sum = Sum,
OperationTime = OperationTime,
SenderCardId = SenderCardId,
RecipientCardId = RecipientCardId,
};
}
}