diff --git a/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs index 99df11a..480a025 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/CardLogic.cs @@ -93,7 +93,7 @@ namespace BankBusinessLogic.BusinessLogic _logger.LogInformation("Card. Number:{Number}." + "Cvv:{ Cvv}. Pin:{ Pin}. Id: { Id} ", model.Number, model.Cvv, model.Pin, model.Id); var element = _cardStorage.GetElement(new CardSearchModel { Number = model.Number }); - if (element != null && element.Id == model.Id) + if (element != null && element.Id != model.Id) throw new InvalidOperationException("Карта с таким номером уже есть"); } } diff --git a/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs b/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs index 5713da0..6203e4f 100644 --- a/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs +++ b/Bank/BankBusinessLogic/BusinessLogic/ClientLogic.cs @@ -94,7 +94,7 @@ namespace BankBusinessLogic.BusinessLogic _logger.LogInformation("Client. ClientFIO:{ClientFIO}." + "Email:{ Email}. Password:{ Password}. Id: { Id} ", model.Fio, model.Email, model.Password, model.Id); var element = _clientStorage.GetElement(new ClientSearchModel { Email = model.Email }); - if (element != null && element.Id == model.Id) + if (element != null && element.Id != model.Id) throw new InvalidOperationException("Клиент с таким логином уже есть"); } } diff --git a/Bank/BankContracts/SearchModels/RequestSearchModel.cs b/Bank/BankContracts/SearchModels/RequestSearchModel.cs index de95ed5..2270880 100644 --- a/Bank/BankContracts/SearchModels/RequestSearchModel.cs +++ b/Bank/BankContracts/SearchModels/RequestSearchModel.cs @@ -10,7 +10,8 @@ namespace BankContracts.SearchModels public class RequestSearchModel { public int? Id { get; set; } - public DateTime? RequestTime { get; set; } + public DateTime? DateFrom { get; set; } + public DateTime? DateTo { get; set; } public string? CardNumber { get; set; } public RequestStatus? Status { get; set; } } diff --git a/Bank/BankDatabaseImplement/Implements/AccountStorage.cs b/Bank/BankDatabaseImplement/Implements/AccountStorage.cs index 958a2e9..79e67f8 100644 --- a/Bank/BankDatabaseImplement/Implements/AccountStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/AccountStorage.cs @@ -45,10 +45,6 @@ namespace BankDatabaseImplement.Implements public AccountViewModel? GetElement(AccountSearchModel model) { using var context = new BankDatabase(); - if (model == null || (!model.Id.HasValue && string.IsNullOrEmpty(model.Number))) - { - return null; - } return context.Accounts .Include(x => x.ManagerId) .Include(x => x.AccountWithdrawals) diff --git a/Bank/BankDatabaseImplement/Implements/CardStorage.cs b/Bank/BankDatabaseImplement/Implements/CardStorage.cs index c537e21..37c76e4 100644 --- a/Bank/BankDatabaseImplement/Implements/CardStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/CardStorage.cs @@ -4,11 +4,6 @@ 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 { @@ -29,7 +24,7 @@ namespace BankDatabaseImplement.Implements .Where(x => ( (!model.Id.HasValue || x.Id == model.Id) && (!model.ClientId.HasValue || x.ClientId == model.ClientId) && - (model.Number == null || x.Number == model.Number) + (string.IsNullOrEmpty(model.Number) || x.Number == model.Number) )) .Select(x => x.GetViewModel) .ToList(); @@ -39,7 +34,8 @@ namespace BankDatabaseImplement.Implements using var context = new BankDatabase(); return context.Cards.Include(x => x.Client).Include(x => x.Account).Include(x => x.CardRequests) .Include(x => x.SenderOperations).Include(x => x.RecipientOperations).FirstOrDefault( - x => (model.Number != null && x.Number == model.Number) + x => ((!model.Id.HasValue || x.Id == model.Id) && + (string.IsNullOrEmpty(model.Number) || x.Number == model.Number)) )?.GetViewModel; } public CardViewModel? Insert(CardBindingModel model) diff --git a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs index 331211a..e03abf0 100644 --- a/Bank/BankDatabaseImplement/Implements/RequestStorage.cs +++ b/Bank/BankDatabaseImplement/Implements/RequestStorage.cs @@ -29,7 +29,10 @@ namespace BankDatabaseImplement.Implements { using var context = new BankDatabase(); return context.Requests.Include(x => x.Cards).ThenInclude(x => x.Card) - .Where(x => (model.Id.HasValue && x.Id == model.Id)).ToList() + .Where(x => (model.Id.HasValue && x.Id == model.Id) && + (!model.DateFrom.HasValue || x.RequestTime >= model.DateFrom) && + (!model.DateTo.HasValue || x.RequestTime <= model.DateTo) + ).ToList() .Select(x => x.GetViewModel).ToList(); } public RequestViewModel? GetElement(RequestSearchModel model) diff --git a/Bank/BankDatabaseImplement/Models/Card.cs b/Bank/BankDatabaseImplement/Models/Card.cs index e9f2c32..7135d13 100644 --- a/Bank/BankDatabaseImplement/Models/Card.cs +++ b/Bank/BankDatabaseImplement/Models/Card.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -13,7 +14,6 @@ namespace BankDatabaseImplement.Models { public class Card : ICardModel { - //убрать интерфейс public int Id { get; set; } [Required] public string Number { get; set; } = string.Empty; @@ -30,7 +30,7 @@ namespace BankDatabaseImplement.Models public virtual Client? Client { get; private set; } [Required] public int? AccountId { get; set; } = null; - public virtual IAccountModel? Account { get; private set; } + public virtual Account? Account { get; private set; } [ForeignKey("CardId")] public virtual List CardRequests { get; set; } = new(); [ForeignKey("SenderCardId")] @@ -47,8 +47,8 @@ namespace BankDatabaseImplement.Models Number = model.Number, Cvv = model.Cvv, Pin = model.Pin, - ReleaseDate = model.ReleaseDate, - ExpirationDate = model.ExpirationDate, + ReleaseDate = DateOnly.FromDateTime(DateTime.Now), + ExpirationDate = DateOnly.FromDateTime(DateTime.Now).AddYears(3), ClientId = model.ClientId, AccountId = model.AccountId, }; diff --git a/Bank/BankDatabaseImplement/Models/Operation.cs b/Bank/BankDatabaseImplement/Models/Operation.cs index 4bd68e9..b0356cb 100644 --- a/Bank/BankDatabaseImplement/Models/Operation.cs +++ b/Bank/BankDatabaseImplement/Models/Operation.cs @@ -31,7 +31,7 @@ namespace BankDatabaseImplement.Models { Id = model.Id, Sum = model.Sum, - OperationTime = model.OperationTime, + OperationTime = DateTime.Now, SenderCardId = model.SenderCardId, RecipientCardId = model.RecipientCardId, }; diff --git a/Bank/BankDatabaseImplement/Models/Request.cs b/Bank/BankDatabaseImplement/Models/Request.cs index 1e971ca..50689ad 100644 --- a/Bank/BankDatabaseImplement/Models/Request.cs +++ b/Bank/BankDatabaseImplement/Models/Request.cs @@ -42,7 +42,7 @@ namespace BankDatabaseImplement.Models { Id = model.Id, Sum = model.Sum, - RequestTime = model.RequestTime, + RequestTime = DateTime.Now, Status = model.Status, Cards = model.CardRequests.Select(x => new CardRequest { @@ -90,6 +90,7 @@ namespace BankDatabaseImplement.Models { Request = Request, Card = context.Cards.First(x => x.Id == request.Key), + Sum = request.Value.Item2 }); context.SaveChanges(); }