diff --git a/ComputerHardwareStore/ComputerHardwareStore.sln b/ComputerHardwareStore/ComputerHardwareStore.sln
index b74e5cc..bdb3461 100644
--- a/ComputerHardwareStore/ComputerHardwareStore.sln
+++ b/ComputerHardwareStore/ComputerHardwareStore.sln
@@ -14,6 +14,9 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreREST", "ComputerHardwareStoreREST\ComputerHardwareStoreREST.csproj", "{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}"
+ ProjectSection(ProjectDependencies) = postProject
+ {D32DEB60-AF40-46AF-8914-DC6A19BD66CD} = {D32DEB60-AF40-46AF-8914-DC6A19BD66CD}
+ EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VendorClient", "VendorClient\VendorClient.csproj", "{BD0D9FB9-7F73-4011-AAC8-D5508EC5EB53}"
EndProject
diff --git a/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/BusinessLogic/MessageInfoLogic.cs b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/BusinessLogic/MessageInfoLogic.cs
new file mode 100644
index 0000000..fba90f6
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/BusinessLogic/MessageInfoLogic.cs
@@ -0,0 +1,20 @@
+using ComputerHardwareContracts.BindingModels;
+using ComputerHardwareStoreContracts.BusinessLogicsContracts;
+using ComputerHardwareStoreContracts.SearchModels;
+using ComputerHardwareStoreContracts.ViewModels;
+
+namespace ComputerHardwareStoreBusinessLogic.BusinessLogic
+{
+ public class MessageInfoLogic : IMessageInfoLogic
+ {
+ public bool Create(MessageInfoBindingModel model)
+ {
+ throw new NotImplementedException();
+ }
+
+ public List? ReadList(MessageInfoSearchModel? model)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/AbstractMailWorker.cs b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/AbstractMailWorker.cs
new file mode 100644
index 0000000..739ebf3
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/AbstractMailWorker.cs
@@ -0,0 +1,62 @@
+using ComputerHardwareStoreContracts.BindingModels;
+using Microsoft.Extensions.Logging;
+
+namespace ComputerHardwareStoreBusinessLogic.MailWorker
+{
+ public abstract class AbstractMailWorker
+ {
+ protected string _mailLogin = string.Empty;
+
+ protected string _mailPassword = string.Empty;
+
+ protected string _smtpClientHost = string.Empty;
+
+ protected int _smtpClientPort;
+
+ protected string _popHost = string.Empty;
+
+ protected int _popPort;
+
+ private readonly ILogger _logger;
+
+ public AbstractMailWorker(ILogger logger)
+ {
+ _logger = logger;
+ }
+
+ public void MailConfig(MailConfigBindingModel config)
+ {
+ _mailLogin = config.MailLogin;
+ _mailPassword = config.MailPassword;
+ _smtpClientHost = config.SmtpClientHost;
+ _smtpClientPort = config.SmtpClientPort;
+ _popHost = config.PopHost;
+ _popPort = config.PopPort;
+ _logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPort}, {popHost}, {popPort}",
+ _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
+ }
+
+ public async void MailSendAsync(MailSendInfoBindingModel info)
+ {
+ if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
+ {
+ return;
+ }
+
+ if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
+ {
+ return;
+ }
+
+ if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
+ {
+ return;
+ }
+
+ _logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
+ await SendMailAsync(info);
+ }
+
+ protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/MailKitWorker.cs b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/MailKitWorker.cs
new file mode 100644
index 0000000..acae297
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreBusinessLogic/MailWorker/MailKitWorker.cs
@@ -0,0 +1,41 @@
+using ComputerHardwareStoreContracts.BindingModels;
+using Microsoft.Extensions.Logging;
+using System.Net;
+using System.Net.Mail;
+using System.Text;
+
+namespace ComputerHardwareStoreBusinessLogic.MailWorker
+{
+ public class MailKitWorker : AbstractMailWorker
+ {
+ public MailKitWorker(ILogger logger) : base(logger) { }
+
+ protected override async Task SendMailAsync(MailSendInfoBindingModel info)
+ {
+ using var objMailMessage = new MailMessage();
+ using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
+ try
+ {
+ objMailMessage.From = new MailAddress(_mailLogin);
+ objMailMessage.To.Add(new MailAddress(info.MailAddress));
+ objMailMessage.Subject = info.Subject;
+ objMailMessage.Body = info.Text;
+ objMailMessage.SubjectEncoding = Encoding.UTF8;
+ objMailMessage.BodyEncoding = Encoding.UTF8;
+ MemoryStream ms = new(info.File);
+ objMailMessage.Attachments.Add(new Attachment(ms, "report.pdf", "application/pdf"));
+
+ objSmtpClient.UseDefaultCredentials = false;
+ objSmtpClient.EnableSsl = true;
+ objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
+ objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
+
+ await Task.Run(() => objSmtpClient.Send(objMailMessage));
+ }
+ catch (Exception)
+ {
+ throw;
+ }
+ }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailConfigBindingModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailConfigBindingModel.cs
new file mode 100644
index 0000000..9a45fb8
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailConfigBindingModel.cs
@@ -0,0 +1,17 @@
+namespace ComputerHardwareStoreContracts.BindingModels
+{
+ public class MailConfigBindingModel
+ {
+ public string MailLogin { get; set; } = string.Empty;
+
+ public string MailPassword { get; set; } = string.Empty;
+ // адрес отправки
+ public string SmtpClientHost { get; set; } = string.Empty;
+
+ public int SmtpClientPort { get; set; }
+ // адрес получения
+ public string PopHost { get; set; } = string.Empty;
+
+ public int PopPort { get; set; }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailSendInfoBindingModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailSendInfoBindingModel.cs
new file mode 100644
index 0000000..b260911
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MailSendInfoBindingModel.cs
@@ -0,0 +1,13 @@
+namespace ComputerHardwareStoreContracts.BindingModels
+{
+ public class MailSendInfoBindingModel
+ {
+ public string MailAddress { get; set; } = string.Empty;
+
+ public string Subject { get; set; } = string.Empty;
+
+ public string Text { get; set; } = string.Empty;
+
+ public byte[] File { get; set; } = Array.Empty();
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MessageInfoBindingModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MessageInfoBindingModel.cs
new file mode 100644
index 0000000..e978f9c
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/BindingModels/MessageInfoBindingModel.cs
@@ -0,0 +1,14 @@
+using ComputerHardwareStoreDataModels.Models;
+
+namespace ComputerHardwareContracts.BindingModels
+{
+ public class MessageInfoBindingModel : IMessageInfoModel
+ {
+ public string MessageId { get; set; } = string.Empty;
+ public int? ClientId { get; set; }
+ public string SenderName { get; set; } = string.Empty;
+ public string Subject { get; set; } = string.Empty;
+ public string Body { get; set; } = string.Empty;
+ public DateTime DateDelivery { get; set; }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/BusinessLogicsContracts/IMessageInfoLogic.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/BusinessLogicsContracts/IMessageInfoLogic.cs
new file mode 100644
index 0000000..c735926
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/BusinessLogicsContracts/IMessageInfoLogic.cs
@@ -0,0 +1,12 @@
+using ComputerHardwareContracts.BindingModels;
+using ComputerHardwareStoreContracts.SearchModels;
+using ComputerHardwareStoreContracts.ViewModels;
+
+namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
+{
+ public interface IMessageInfoLogic
+ {
+ List? ReadList(MessageInfoSearchModel? model);
+ bool Create(MessageInfoBindingModel model);
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/ComputerHardwareStoreContracts.csproj b/ComputerHardwareStore/ComputerHardwareStoreContracts/ComputerHardwareStoreContracts.csproj
index 4e4937a..a9000d8 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreContracts/ComputerHardwareStoreContracts.csproj
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/ComputerHardwareStoreContracts.csproj
@@ -6,6 +6,10 @@
enable
+
+
+
+
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/MessageInfoSearchModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/MessageInfoSearchModel.cs
new file mode 100644
index 0000000..70ea72e
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/MessageInfoSearchModel.cs
@@ -0,0 +1,8 @@
+namespace ComputerHardwareStoreContracts.SearchModels
+{
+ public class MessageInfoSearchModel
+ {
+ public int? ClientId { get; set; }
+ public string? MessageId { get; set; }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/StoreKeeperSearchModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/StoreKeeperSearchModel.cs
index 21c4265..a59938a 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/StoreKeeperSearchModel.cs
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/SearchModels/StoreKeeperSearchModel.cs
@@ -4,5 +4,6 @@
{
public int? Id { get; set; }
public string? Login { get; set; }
- }
+ public string? Password { get; set; }
+ }
}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/StorageContracts/IMessageInfoStorage.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/StorageContracts/IMessageInfoStorage.cs
new file mode 100644
index 0000000..e089c2d
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/StorageContracts/IMessageInfoStorage.cs
@@ -0,0 +1,14 @@
+using ComputerHardwareContracts.BindingModels;
+using ComputerHardwareStoreContracts.SearchModels;
+using ComputerHardwareStoreContracts.ViewModels;
+
+namespace ComputerHardwareStoreContracts.StorageContracts
+{
+ public interface IMessageInfoStorage
+ {
+ List GetFullList();
+ List GetFilteredList(MessageInfoSearchModel model);
+ MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
+ MessageInfoViewModel? Insert(MessageInfoBindingModel model);
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/MessageInfoViewModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/MessageInfoViewModel.cs
new file mode 100644
index 0000000..171fea3
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/MessageInfoViewModel.cs
@@ -0,0 +1,24 @@
+using ComputerHardwareStoreDataModels.Models;
+using System.ComponentModel;
+
+namespace ComputerHardwareStoreContracts.ViewModels
+{
+ public class MessageInfoViewModel : IMessageInfoModel
+ {
+ public string MessageId { get; set; } = string.Empty;
+
+ public int? ClientId { get; set; }
+
+ [DisplayName("Отправитель")]
+ public string SenderName { get; set; } = string.Empty;
+
+ [DisplayName("Дата письма")]
+ public DateTime DateDelivery { get; set; }
+
+ [DisplayName("Заголовок")]
+ public string Subject { get; set; } = string.Empty;
+
+ [DisplayName("Текст")]
+ public string Body { get; set; } = string.Empty;
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ReportPurchaseViewModel.cs b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ReportPurchaseViewModel.cs
new file mode 100644
index 0000000..43ee4b8
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreContracts/ViewModels/ReportPurchaseViewModel.cs
@@ -0,0 +1,13 @@
+namespace ComputerHardwareStoreContracts.ViewModels
+{
+ public class ReportPurchaseViewModel
+ {
+ public int Id { get; set; }
+
+ public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new();
+
+ public int TotalCount { get; set; }
+
+ public double TotalCost { get; set; }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IMessageInfoModel.cs b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IMessageInfoModel.cs
new file mode 100644
index 0000000..ec51d4f
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreDataModels/Models/IMessageInfoModel.cs
@@ -0,0 +1,12 @@
+namespace ComputerHardwareStoreDataModels.Models
+{
+ public interface IMessageInfoModel
+ {
+ string MessageId { get; }
+ int? ClientId { get; }
+ string SenderName { get; }
+ DateTime DateDelivery { get; }
+ string Subject { get; }
+ string Body { get; }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs
index fb2b5b2..418fdab 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs
+++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/StoreKeepersController.cs
@@ -2,87 +2,82 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.StorageContracts;
+using ComputerHardwareStoreContracts.BusinessLogicsContracts;
+using ComputerHardwareStoreContracts.ViewModels;
namespace ComputerHardwareStoreREST.Controllers
{
- [ApiController]
- [Route("[controller]")]
- public class StoreKeepersController : Controller
+ [Route("api/[controller]/[action]")]
+ [ApiController]
+ public class StoreKeeperController : Controller
{
- private readonly ILogger _logger;
- private readonly IStoreKeeperStorage _storage;
-
- public StoreKeepersController(ILogger logger, IStoreKeeperStorage storage)
- {
- _logger = logger;
- _storage = storage;
- }
-
- [HttpPost("get/filter")]
- public IActionResult GetByFilter([FromBody] StoreKeeperSearchModel model)
- {
- try
- {
- var result = _storage.GetFilteredList(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("get")]
- public IActionResult GetById([FromBody] StoreKeeperSearchModel model)
- {
- try
- {
- var result = _storage.GetElement(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("create")]
- public IActionResult Create([FromBody] StoreKeeperBindingModel model)
- {
- try
- {
- var result = _storage.Insert(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPut("update")]
- public IActionResult Update([FromBody] StoreKeeperBindingModel model)
- {
- try
- {
- var result = _storage.Update(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("delete")]
- public IActionResult Delete([FromBody] StoreKeeperBindingModel model)
- {
- try
- {
- var result = _storage.Delete(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
-
- }
- }
+ private readonly ILogger _logger;
+ private readonly IStoreKeeperLogic _logic;
+ private readonly IMessageInfoLogic _mailLogic;
+ public StoreKeeperController(IStoreKeeperLogic logic, IMessageInfoLogic mailLogic, ILogger logger)
+ {
+ _logger = logger;
+ _logic = logic;
+ _mailLogic = mailLogic;
+ }
+ [HttpGet]
+ public StoreKeeperViewModel? Login(string login, string password)
+ {
+ try
+ {
+ return _logic.ReadElement(new StoreKeeperSearchModel
+ {
+ Login = login,
+ Password = password
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка входа в систему");
+ throw;
+ }
+ }
+ [HttpPost]
+ public void Register(StoreKeeperBindingModel model)
+ {
+ try
+ {
+ _logic.Create(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка регистрации");
+ throw;
+ }
+ }
+ [HttpPost]
+ public void UpdateData(StoreKeeperBindingModel model)
+ {
+ try
+ {
+ _logic.Update(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка обновления данных");
+ throw;
+ }
+ }
+ [HttpGet]
+ public List? GetMessages(int clientId)
+ {
+ try
+ {
+ return _mailLogic.ReadList(new MessageInfoSearchModel
+ {
+ ClientId = clientId
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения писем клиента");
+ throw;
+ }
+ }
+ }
}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs
index 3e21627..91a4dbc 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs
+++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Controllers/VendorController.cs
@@ -1,87 +1,82 @@
using ComputerHardwareStoreContracts.BindingModels;
+using ComputerHardwareStoreContracts.BusinessLogicsContracts;
using ComputerHardwareStoreContracts.SearchModels;
-using ComputerHardwareStoreContracts.StorageContracts;
+using ComputerHardwareStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
namespace ComputerHardwareStoreREST.Controllers
{
- [ApiController]
- [Route("[controller]")]
+ [Route("api/[controller]/[action]")]
+ [ApiController]
public class VendorController : Controller
{
- private readonly ILogger _logger;
- private readonly IVendorStorage _storage;
-
- public VendorController(ILogger logger, IVendorStorage storage)
- {
- _logger = logger;
- _storage = storage;
- }
-
- [HttpPost("get/filter")]
- public IActionResult GetByFilter([FromBody] VendorSearchModel model)
- {
- try
- {
- var result = _storage.GetFilteredList(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("get")]
- public IActionResult GetById([FromBody] VendorSearchModel model)
- {
- try
- {
- var result = _storage.GetElement(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("create")]
- public IActionResult Create([FromBody] VendorBindingModel model)
- {
- try
- {
- var result = _storage.Insert(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPut("update")]
- public IActionResult Update([FromBody] VendorBindingModel model)
- {
- try
- {
- var result = _storage.Update(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- [HttpPost("delete")]
- public IActionResult Delete([FromBody] VendorBindingModel model)
- {
- try
- {
- var result = _storage.Delete(model);
- return Ok(result);
- }
- catch (Exception ex)
- {
- return BadRequest(ex.Message);
- }
- }
- }
+ private readonly ILogger _logger;
+ private readonly IVendorLogic _logic;
+ private readonly IMessageInfoLogic _mailLogic;
+ public VendorController(IVendorLogic logic, IMessageInfoLogic mailLogic, ILogger logger)
+ {
+ _logger = logger;
+ _logic = logic;
+ _mailLogic = mailLogic;
+ }
+ [HttpGet]
+ public VendorViewModel? Login(string login, string password)
+ {
+ try
+ {
+ return _logic.ReadElement(new VendorSearchModel
+ {
+ Login = login,
+ Password = password
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка входа в систему");
+ throw;
+ }
+ }
+ [HttpPost]
+ public void Register(VendorBindingModel model)
+ {
+ try
+ {
+ _logic.Create(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка регистрации");
+ throw;
+ }
+ }
+ [HttpPost]
+ public void UpdateData(VendorBindingModel model)
+ {
+ try
+ {
+ _logic.Update(model);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка обновления данных");
+ throw;
+ }
+ }
+ [HttpGet]
+ public List? GetMessages(int clientId)
+ {
+ try
+ {
+ return _mailLogic.ReadList(new MessageInfoSearchModel
+ {
+ ClientId = clientId
+ });
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка получения писем клиента");
+ throw;
+ }
+ }
+ }
}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/Program.cs b/ComputerHardwareStore/ComputerHardwareStoreREST/Program.cs
index eeea455..abbc85e 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreREST/Program.cs
+++ b/ComputerHardwareStore/ComputerHardwareStoreREST/Program.cs
@@ -1,7 +1,6 @@
using ComputerHardwareStoreBusinessLogic.BusinessLogic;
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
using ComputerHardwareStoreContracts.StorageContracts;
-using ComputerHardwareStoreDatabaseImplement;
using ComputerHardwareStoreDatabaseImplement.Implements;
using ComputerHardwareStoreREST;
using Microsoft.EntityFrameworkCore;
@@ -36,12 +35,21 @@ builder.Services.AddTransient();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
-
+var mailSender = app.Services.GetService();
+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())
+});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
- app.UseSwagger();
- app.UseSwaggerUI();
+ app.UseSwagger();
+ app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AbstractShopRestApi v1"));
}
app.UseHttpsRedirection();
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.Development.json b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.Development.json
new file mode 100644
index 0000000..0c208ae
--- /dev/null
+++ b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.Development.json
@@ -0,0 +1,8 @@
+{
+ "Logging": {
+ "LogLevel": {
+ "Default": "Information",
+ "Microsoft.AspNetCore": "Warning"
+ }
+ }
+}
diff --git a/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json
index 03b4c0d..34ed940 100644
--- a/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json
+++ b/ComputerHardwareStore/ComputerHardwareStoreREST/appsettings.json
@@ -5,5 +5,12 @@
"Microsoft.AspNetCore": "Warning"
}
},
- "AllowedHosts": "*"
-}
\ No newline at end of file
+ "AllowedHosts": "*",
+
+ "SmtpClientHost": "smtp.gmail.com",
+ "SmtpClientPort": "587",
+ "PopHost": "pop.gmail.com",
+ "PopPort": "995",
+ "MailLogin": "coursework@gmail.com",
+ "MailPassword": "123"
+}
diff --git a/ComputerHardwareStore/StoreKeeperClient/APIClient.cs b/ComputerHardwareStore/StoreKeeperClient/APIClient.cs
index 9451b75..69d36ec 100644
--- a/ComputerHardwareStore/StoreKeeperClient/APIClient.cs
+++ b/ComputerHardwareStore/StoreKeeperClient/APIClient.cs
@@ -15,6 +15,7 @@ namespace StoreKeeperClient
_client.DefaultRequestHeaders.Accept.Clear();
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
+
public static T? GetRequest(string requestUrl)
{
var response = _client.GetAsync(requestUrl);
@@ -28,16 +29,37 @@ namespace StoreKeeperClient
throw new Exception(result);
}
}
+
public static void PostRequest(string requestUrl, T model)
{
var json = JsonConvert.SerializeObject(model);
var data = new StringContent(json, Encoding.UTF8, "application/json");
+
var response = _client.PostAsync(requestUrl, data);
+
var result = response.Result.Content.ReadAsStringAsync().Result;
if (!response.Result.IsSuccessStatusCode)
{
throw new Exception(result);
}
}
+
+ public static R? PostRequestWithResult(string requestUrl, T model)
+ {
+ var json = JsonConvert.SerializeObject(model);
+ var data = new StringContent(json, Encoding.UTF8, "application/json");
+
+ var response = _client.PostAsync(requestUrl, data);
+
+ var result = response.Result.Content.ReadAsStringAsync().Result;
+ if (response.Result.IsSuccessStatusCode)
+ {
+ return JsonConvert.DeserializeObject(result);
+ }
+ else
+ {
+ return default;
+ }
+ }
}
}
diff --git a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs
index 5a901a4..70b20c8 100644
--- a/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs
+++ b/ComputerHardwareStore/StoreKeeperClient/Controllers/HomeController.cs
@@ -233,7 +233,16 @@ namespace StoreKeeperClient.Controllers
Response.Redirect("ReportOnly");
}
- [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
+ public IActionResult Mails()
+ {
+ if (APIClient.Client == null)
+ {
+ return Redirect("~/Home/Enter");
+ }
+ return View(APIClient.GetRequest>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
+ }
+
+ [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Home/Mails.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Mails.cshtml
new file mode 100644
index 0000000..8221b46
--- /dev/null
+++ b/ComputerHardwareStore/StoreKeeperClient/Views/Home/Mails.cshtml
@@ -0,0 +1,48 @@
+@using ComputerHardwareStoreContracts.ViewModels
+@model List
+@{
+ ViewData["Title"] = "Mails";
+}
+
+
Заказы
+
+
+ @{
+ if (Model == null)
+ {
+
Авторизируйтесь
+ return;
+ }
+
+
+
+
+ Дата письма
+
+
+ Заголовок
+
+
+ Текст
+
+
+
+
+ @foreach (var item in Model)
+ {
+
+
+ @Html.DisplayFor(modelItem => item.DateDelivery)
+
+
+ @Html.DisplayFor(modelItem => item.Subject)
+
+
+ @Html.DisplayFor(modelItem => item.Body)
+
+
+ }
+
+
+ }
+
diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/Error.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/Error.cshtml
index a1e0478..4d96f6a 100644
--- a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/Error.cshtml
+++ b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/Error.cshtml
@@ -22,4 +22,4 @@
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the Development environment by setting the ASPNETCORE_ENVIRONMENT environment variable to Development
and restarting the app.
-
+
\ No newline at end of file
diff --git a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml
index 9feb1d3..93d0db2 100644
--- a/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml
+++ b/ComputerHardwareStore/StoreKeeperClient/Views/Shared/_Layout.cshtml
@@ -1,34 +1,34 @@
-
-
+
+
@ViewData["Title"] - ComputerStoreWorkerApp
-
+
-
+
+
+ @RenderBody()
+
+
-
-
+
@await RenderSectionAsync("Scripts", required: false)
-
+