Messages DatabaseImplement
This commit is contained in:
parent
a5df68d9df
commit
505a708ddf
36
AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs
Normal file
36
AutoWorkshopBusinessLogic/BusinessLogics/MessageInfoLogic.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
{
|
||||
public class MessageInfoLogic : IMessageInfoLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IMessageInfoStorage _messageInfoStorage;
|
||||
private readonly IClientStorage _clientStorage;
|
||||
|
||||
public MessageInfoLogic(ILogger Logger, IMessageInfoStorage MessageInfoStorage, IClientStorage ClientStorage)
|
||||
{
|
||||
_logger = Logger;
|
||||
_messageInfoStorage = MessageInfoStorage;
|
||||
_clientStorage = ClientStorage;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? Model)
|
||||
{
|
||||
// TODO
|
||||
return new();
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel Model)
|
||||
{
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class MailConfigBindingModel
|
||||
public class MailConfigBindingModel
|
||||
{
|
||||
public string MailLogin { get; set; } = string.Empty;
|
||||
|
||||
|
@ -1,12 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
namespace AutoWorkshopContracts.BindingModels
|
||||
{
|
||||
public class MailSendInfoBindingModel
|
||||
public class MailSendInfoBindingModel
|
||||
{
|
||||
public string MailAddress { get; set; } = string.Empty;
|
||||
|
||||
|
@ -5,7 +5,5 @@
|
||||
public string? MessageId { get; set; }
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string? SenderName { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,9 @@ namespace AutoWorkshopContracts.ViewModels
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Почта клиента")]
|
||||
public string ClientEmail { get; set; } = string.Empty;
|
||||
|
||||
public int? ImplementerId { get; set; }
|
||||
|
||||
[DisplayName("Исполнитель")]
|
||||
|
@ -29,5 +29,7 @@ namespace AutoWorkshopDatabaseImplement
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
|
||||
public virtual DbSet<MessageInfo> Messages { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Messages
|
||||
.Where(x => x.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.MessageId))
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Messages
|
||||
.FirstOrDefault(x => x.MessageId == Model.MessageId)?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel Model)
|
||||
{
|
||||
var NewMessageInfo = MessageInfo.Create(Model);
|
||||
|
||||
if (NewMessageInfo == null)
|
||||
return null;
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
Context.Messages.Add(NewMessageInfo);
|
||||
|
||||
Context.SaveChanges();
|
||||
return NewMessageInfo.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
public virtual List<Order> ClientOrders { get; set; } = new();
|
||||
|
||||
[ForeignKey("ClientId")]
|
||||
public virtual List<MessageInfo> ClientMessages { get; set; } = new();
|
||||
|
||||
public static Client? Create(ClientBindingModel Model)
|
||||
{
|
||||
|
47
AutoWorkshopDatabaseImplement/Models/MessageInfo.cs
Normal file
47
AutoWorkshopDatabaseImplement/Models/MessageInfo.cs
Normal file
@ -0,0 +1,47 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
public string MessageId { get; set; } = string.Empty;
|
||||
|
||||
public int? ClientId { get; set; }
|
||||
|
||||
public string SenderName { get; set; } = string.Empty;
|
||||
|
||||
public DateTime DateDelivery { get; set; }
|
||||
|
||||
public string Subject { get; set; } = string.Empty;
|
||||
|
||||
public string Body { get; set; } = string.Empty;
|
||||
|
||||
public static MessageInfo? Create(MessageInfoBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new()
|
||||
{
|
||||
MessageId = Model.MessageId,
|
||||
ClientId = Model.ClientId,
|
||||
SenderName = Model.SenderName,
|
||||
DateDelivery = Model.DateDelivery,
|
||||
Subject = Model.Subject,
|
||||
Body = Model.Body
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
MessageId = MessageId,
|
||||
ClientId = ClientId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
Subject = Subject,
|
||||
Body = Body
|
||||
};
|
||||
}
|
||||
}
|
@ -75,6 +75,7 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
ImplementerId = ImplementerId,
|
||||
RepairName = Repair.RepairName,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ClientEmail = Client.Email,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
|
@ -1,4 +1,6 @@
|
||||
using AutoWorkshopBusinessLogic.BusinessLogics;
|
||||
using AutoWorkshopBusinessLogic.MailWorker;
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.BusinessLogicContracts;
|
||||
using AutoWorkshopContracts.BusinessLogicsContracts;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
@ -14,11 +16,15 @@ Builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
||||
Builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
Builder.Services.AddTransient<IRepairStorage, RepairStorage>();
|
||||
Builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
Builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
|
||||
Builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
Builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
Builder.Services.AddTransient<IRepairLogic, RepairLogic>();
|
||||
Builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
Builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
|
||||
Builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
Builder.Services.AddControllers();
|
||||
|
||||
@ -34,6 +40,18 @@ Builder.Services.AddSwaggerGen(c =>
|
||||
|
||||
var App = Builder.Build();
|
||||
|
||||
var MailSender = App.Services.GetService<AbstractMailWorker>();
|
||||
MailSender?.MailConfig(new MailConfigBindingModel
|
||||
{
|
||||
MailLogin = Builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||
MailPassword = Builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientHost = Builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||
SmtpClientPort = Convert.ToInt32(Builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||
PopHost = Builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||
PopPort = Convert.ToInt32(Builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||
});
|
||||
|
||||
|
||||
if (App.Environment.IsDevelopment())
|
||||
{
|
||||
App.UseSwagger();
|
||||
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"SmtpClientHost": "smtp.gmail.com",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "pasxalko1488ventilyator@gmail.com",
|
||||
"MailPassword": "MsCutiePatootie"
|
||||
}
|
||||
|
11
AutoWorkshopView/App.config
Normal file
11
AutoWorkshopView/App.config
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="SmtpClientHost" value="smtp.gmail.com" />
|
||||
<add key="SmtpClientPort" value="587" />
|
||||
<add key="PopHost" value="pop.gmail.com" />
|
||||
<add key="PopPort" value="995" />
|
||||
<add key="MailLogin" value="pasxalko1488ventilyator@gmail.com" />
|
||||
<add key="MailPassword" value="MsCutiePatootie" />
|
||||
</appSettings>
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user