Eliseev E.E. LabWork07_Hard #17

Closed
ElEgEv wants to merge 26 commits from LabWork07_Hard into LabWork06_Hard
10 changed files with 23 additions and 27 deletions
Showing only changes of commit 593ecd9c08 - Show all commits

View File

@ -74,6 +74,7 @@ namespace BlacksmithWorkshopRestApi.Controllers
}
}
[HttpGet]
public List<MessageInfoViewModel>? GetMessages(int clientId)
{
try

View File

@ -26,7 +26,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
_logger.LogInformation("ReadList. SenderName:{SenderName}. MessageId:{MessageId}", model?.SenderName, model?.MessageId);
_logger.LogInformation("ReadList. MessageId:{MessageId}", model?.MessageId);
//list хранит весь список в случае, если model пришло со значением null на вход метода
var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
@ -44,7 +44,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
public bool Create(MessageInfoBindingModel model)
{
CheckModel(model);
//CheckModel(model);
if (_messageInfoStorage.Insert(model) == null)
{
@ -57,7 +57,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
}
//проверка входного аргумента для методов Insert, Update и Delete
private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
/*private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
{
if (model == null)
{
@ -109,6 +109,6 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
{
throw new InvalidOperationException("Аккаунт с таким логином уже есть");
}
}
}*/
}
}

View File

@ -25,12 +25,15 @@ namespace BlacksmithWorkshopBusinessLogic.MailWorker
private readonly IMessageInfoLogic _messageInfoLogic;
private readonly IClientLogic _clientLogic;
private readonly ILogger _logger;
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic)
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
{
_logger = logger;
_messageInfoLogic = messageInfoLogic;
_clientLogic = clientLogic;
}
public void MailConfig(MailConfigBindingModel config)
@ -91,14 +94,14 @@ namespace BlacksmithWorkshopBusinessLogic.MailWorker
foreach (var mail in list)
{
mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id;
_messageInfoLogic.Create(mail);
}
}
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
protected abstract Task<List<MessageInfoBindingModel>>
ReceiveMailAsync();
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
}
}

View File

@ -15,7 +15,8 @@ namespace BlacksmithWorkshopBusinessLogic.MailWorker
{
public class MailKitWorker : AbstractMailWorker
{
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic) : base(logger, messageInfoLogic) { }
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
: base(logger, messageInfoLogic, clientLogic) { }
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
{
@ -31,6 +32,7 @@ namespace BlacksmithWorkshopBusinessLogic.MailWorker
objMailMessage.Body = info.Text;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.EnableSsl = true;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

View File

@ -9,7 +9,7 @@
<div class="row">
<div class="col-4">Логин:</div>
<div class="col-8">
<input type="text" name="login" /
<input type="text" name="login" />
</div>
</div>
<div class="row">

View File

@ -11,9 +11,5 @@ namespace BlacksmithWorkshopContracts.SearchModels
public string? MessageId { get; set; }
public int? ClientId { get; set; }
public string? SenderName { get; set; }
public DateTime? DateDelivery { get; set; }
}
}

View File

@ -20,7 +20,6 @@ namespace BlacksmithWorkshopContracts.ViewModels
[DisplayName("Дата отправки")]
public DateTime DateDelivery { get; set; } = DateTime.Now;
[DisplayName("Заголовок")]
public string Subject { get; set; } = string.Empty;

View File

@ -32,15 +32,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
{
using var context = new BlacksmithWorkshopDatabase();
if (!model.ClientId.HasValue)
{
return context.Messages
.Select(x => x.GetViewModel)
.ToList();
}
return context.Messages
.Where(x => x.ClientId == model.ClientId)
.Where(x => x.ClientId.HasValue && x.ClientId == model.ClientId)
.Select(x => x.GetViewModel)
.ToList();
}
@ -68,9 +61,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
context.Messages.Add(newMessage);
context.SaveChanges();
return context.Messages
.FirstOrDefault(x => x.MessageId == newMessage.MessageId)
?.GetViewModel;
return newMessage.GetViewModel;
}
}
}

View File

@ -28,6 +28,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<MessageInfo> MessageInfos { get; set; } = new();
public static Client? Create(ClientBindingModel model)
{
if (model == null)

View File

@ -15,7 +15,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[Key]
public string MessageId { get; private set; } = string.Empty;
[Required]
public int? ClientId { get; private set; }
[Required]
@ -30,6 +29,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
[Required]
public string Body { get; private set; } = string.Empty;
public virtual Client? Client { get; set; }
public static MessageInfo? Create(MessageInfoBindingModel model)
{
if (model == null)