Обсудили вопросы

This commit is contained in:
Artyom_Yashin 2024-04-28 23:23:21 +04:00
parent ee88e831c4
commit b3104e5d1a
9 changed files with 18 additions and 21 deletions

View File

@ -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("Карта с таким номером уже есть");
}
}

View File

@ -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("Клиент с таким логином уже есть");
}
}

View File

@ -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; }
}

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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<CardRequest> 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,
};

View File

@ -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,
};

View File

@ -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();
}