сдала... :_)
This commit is contained in:
parent
f0ac52e9ee
commit
c5525345d6
@ -12,15 +12,25 @@ namespace SushiBarBusinessLogic
|
||||
|
||||
private readonly ILogger logger;
|
||||
private readonly IMessageInfoStorage messageStorage;
|
||||
private readonly IClientLogic clientLogic;
|
||||
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage)
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage, IClientLogic clientLogic)
|
||||
{
|
||||
this.logger = logger;
|
||||
this.messageStorage = messageStorage;
|
||||
this.clientLogic = clientLogic;
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if(messageStorage.Insert(model) == null)
|
||||
var message = messageStorage.GetElement(new MessageInfoSearchModel { MessageId = model.MessageId});
|
||||
if (message != null) return false;
|
||||
var client = clientLogic.ReadElement(new ClientSearchModel{ Email = model.SenderName });
|
||||
if (client != null)
|
||||
{
|
||||
model.ClientId = client.Id;
|
||||
}
|
||||
if (messageStorage.Insert(model) == null)
|
||||
{
|
||||
logger.LogWarning("Insert message operation failed");
|
||||
return false;
|
||||
@ -31,7 +41,7 @@ namespace SushiBarBusinessLogic
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||
{
|
||||
var list = model == null ? messageStorage.GetFullList() : messageStorage.GetFilteredList(model);
|
||||
if(list == null)
|
||||
if (list == null)
|
||||
{
|
||||
logger.LogWarning("ReadList had returned a null list");
|
||||
return null;
|
||||
|
@ -71,7 +71,8 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
var clientView = clientStorage.GetElement(new() { Id = order.ClientId });
|
||||
|
||||
var clientView = clientStorage.GetElement(new ClientSearchModel() { Id = order.ClientId });
|
||||
|
||||
if (clientView != null)
|
||||
SendMail(clientView, order);
|
||||
|
@ -37,15 +37,16 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
public ClientViewModel? Delete(ClientBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
var element = context.Clients.FirstOrDefault(c => c.Id == model.Id);
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
|
||||
}
|
||||
context.Clients.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||
{
|
||||
|
@ -50,9 +50,8 @@ namespace SushiBarDatabaseImplement.Implements
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new SushiBarDatabase();
|
||||
model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id;
|
||||
var message = MessageInfo.Create(model);
|
||||
if (message == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
|
||||
if (message == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
@ -13,6 +13,5 @@
|
||||
"PopHost": "pop.beget.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "sushishop@ekallin.ru",
|
||||
"MailPassword": "8j#HWiCBiI*I!"
|
||||
"MailPassword": "8j#HWiCBiI*I"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user