работа-работа, перейди на
This commit is contained in:
parent
bbf04c8cc0
commit
46f93270fe
@ -14,6 +14,9 @@ EndProject
|
|||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreDatabaseImplement", "ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj", "{93BD4E28-48D8-4D3A-87FB-FB96F00DA64B}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputerHardwareStoreREST", "ComputerHardwareStoreREST\ComputerHardwareStoreREST.csproj", "{20E4D287-C0F4-4DAB-B338-349F8B6EA22B}"
|
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
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VendorClient", "VendorClient\VendorClient.csproj", "{BD0D9FB9-7F73-4011-AAC8-D5508EC5EB53}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VendorClient", "VendorClient\VendorClient.csproj", "{BD0D9FB9-7F73-4011-AAC8-D5508EC5EB53}"
|
||||||
EndProject
|
EndProject
|
||||||
|
@ -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<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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<AbstractMailWorker> 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);
|
||||||
|
}
|
||||||
|
}
|
@ -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<MailKitWorker> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -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<byte>();
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using ComputerHardwareContracts.BindingModels;
|
||||||
|
using ComputerHardwareStoreContracts.SearchModels;
|
||||||
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace ComputerHardwareStoreContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IMessageInfoLogic
|
||||||
|
{
|
||||||
|
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||||
|
bool Create(MessageInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
namespace ComputerHardwareStoreContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class MessageInfoSearchModel
|
||||||
|
{
|
||||||
|
public int? ClientId { get; set; }
|
||||||
|
public string? MessageId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Login { get; set; }
|
public string? Login { get; set; }
|
||||||
}
|
public string? Password { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
using ComputerHardwareContracts.BindingModels;
|
||||||
|
using ComputerHardwareStoreContracts.SearchModels;
|
||||||
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace ComputerHardwareStoreContracts.StorageContracts
|
||||||
|
{
|
||||||
|
public interface IMessageInfoStorage
|
||||||
|
{
|
||||||
|
List<MessageInfoViewModel> GetFullList();
|
||||||
|
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||||
|
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||||
|
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -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; }
|
||||||
|
}
|
||||||
|
}
|
@ -20,6 +20,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
|
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -2,87 +2,82 @@
|
|||||||
using ComputerHardwareStoreContracts.BindingModels;
|
using ComputerHardwareStoreContracts.BindingModels;
|
||||||
using ComputerHardwareStoreContracts.SearchModels;
|
using ComputerHardwareStoreContracts.SearchModels;
|
||||||
using ComputerHardwareStoreContracts.StorageContracts;
|
using ComputerHardwareStoreContracts.StorageContracts;
|
||||||
|
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
|
|
||||||
namespace ComputerHardwareStoreREST.Controllers
|
namespace ComputerHardwareStoreREST.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[Route("api/[controller]/[action]")]
|
||||||
[Route("[controller]")]
|
[ApiController]
|
||||||
public class StoreKeepersController : Controller
|
public class StoreKeeperController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<StoreKeepersController> _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IStoreKeeperStorage _storage;
|
private readonly IStoreKeeperLogic _logic;
|
||||||
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
public StoreKeepersController(ILogger<StoreKeepersController> logger, IStoreKeeperStorage storage)
|
public StoreKeeperController(IStoreKeeperLogic logic, IMessageInfoLogic mailLogic, ILogger<StoreKeeperController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_storage = storage;
|
_logic = logic;
|
||||||
}
|
_mailLogic = mailLogic;
|
||||||
|
}
|
||||||
[HttpPost("get/filter")]
|
[HttpGet]
|
||||||
public IActionResult GetByFilter([FromBody] StoreKeeperSearchModel model)
|
public StoreKeeperViewModel? Login(string login, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = _storage.GetFilteredList(model);
|
return _logic.ReadElement(new StoreKeeperSearchModel
|
||||||
return Ok(result);
|
{
|
||||||
}
|
Login = login,
|
||||||
catch (Exception ex)
|
Password = password
|
||||||
{
|
});
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPost("get")]
|
_logger.LogError(ex, "Ошибка входа в систему");
|
||||||
public IActionResult GetById([FromBody] StoreKeeperSearchModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpPost]
|
||||||
var result = _storage.GetElement(model);
|
public void Register(StoreKeeperBindingModel model)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logic.Create(model);
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPost("create")]
|
_logger.LogError(ex, "Ошибка регистрации");
|
||||||
public IActionResult Create([FromBody] StoreKeeperBindingModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpPost]
|
||||||
var result = _storage.Insert(model);
|
public void UpdateData(StoreKeeperBindingModel model)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logic.Update(model);
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPut("update")]
|
_logger.LogError(ex, "Ошибка обновления данных");
|
||||||
public IActionResult Update([FromBody] StoreKeeperBindingModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpGet]
|
||||||
var result = _storage.Update(model);
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||||
return BadRequest(ex.Message);
|
{
|
||||||
}
|
ClientId = clientId
|
||||||
}
|
});
|
||||||
[HttpPost("delete")]
|
}
|
||||||
public IActionResult Delete([FromBody] StoreKeeperBindingModel model)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||||
{
|
throw;
|
||||||
var result = _storage.Delete(model);
|
}
|
||||||
return Ok(result);
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(ex.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,87 +1,82 @@
|
|||||||
using ComputerHardwareStoreContracts.BindingModels;
|
using ComputerHardwareStoreContracts.BindingModels;
|
||||||
|
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||||
using ComputerHardwareStoreContracts.SearchModels;
|
using ComputerHardwareStoreContracts.SearchModels;
|
||||||
using ComputerHardwareStoreContracts.StorageContracts;
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace ComputerHardwareStoreREST.Controllers
|
namespace ComputerHardwareStoreREST.Controllers
|
||||||
{
|
{
|
||||||
[ApiController]
|
[Route("api/[controller]/[action]")]
|
||||||
[Route("[controller]")]
|
[ApiController]
|
||||||
public class VendorController : Controller
|
public class VendorController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<VendorController> _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IVendorStorage _storage;
|
private readonly IVendorLogic _logic;
|
||||||
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
public VendorController(ILogger<VendorController> logger, IVendorStorage storage)
|
public VendorController(IVendorLogic logic, IMessageInfoLogic mailLogic, ILogger<VendorController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_storage = storage;
|
_logic = logic;
|
||||||
}
|
_mailLogic = mailLogic;
|
||||||
|
}
|
||||||
[HttpPost("get/filter")]
|
[HttpGet]
|
||||||
public IActionResult GetByFilter([FromBody] VendorSearchModel model)
|
public VendorViewModel? Login(string login, string password)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = _storage.GetFilteredList(model);
|
return _logic.ReadElement(new VendorSearchModel
|
||||||
return Ok(result);
|
{
|
||||||
}
|
Login = login,
|
||||||
catch (Exception ex)
|
Password = password
|
||||||
{
|
});
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPost("get")]
|
_logger.LogError(ex, "Ошибка входа в систему");
|
||||||
public IActionResult GetById([FromBody] VendorSearchModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpPost]
|
||||||
var result = _storage.GetElement(model);
|
public void Register(VendorBindingModel model)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logic.Create(model);
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPost("create")]
|
_logger.LogError(ex, "Ошибка регистрации");
|
||||||
public IActionResult Create([FromBody] VendorBindingModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpPost]
|
||||||
var result = _storage.Insert(model);
|
public void UpdateData(VendorBindingModel model)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logic.Update(model);
|
||||||
return BadRequest(ex.Message);
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
}
|
{
|
||||||
[HttpPut("update")]
|
_logger.LogError(ex, "Ошибка обновления данных");
|
||||||
public IActionResult Update([FromBody] VendorBindingModel model)
|
throw;
|
||||||
{
|
}
|
||||||
try
|
}
|
||||||
{
|
[HttpGet]
|
||||||
var result = _storage.Update(model);
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||||
return Ok(result);
|
{
|
||||||
}
|
try
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||||
return BadRequest(ex.Message);
|
{
|
||||||
}
|
ClientId = clientId
|
||||||
}
|
});
|
||||||
[HttpPost("delete")]
|
}
|
||||||
public IActionResult Delete([FromBody] VendorBindingModel model)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
try
|
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||||
{
|
throw;
|
||||||
var result = _storage.Delete(model);
|
}
|
||||||
return Ok(result);
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return BadRequest(ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
using ComputerHardwareStoreContracts.StorageContracts;
|
using ComputerHardwareStoreBusinessLogic.BusinessLogic;
|
||||||
using ComputerHardwareStoreDatabaseImplement;
|
using ComputerHardwareStoreBusinessLogic.MailWorker;
|
||||||
|
using ComputerHardwareStoreContracts.BindingModels;
|
||||||
|
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||||
|
using ComputerHardwareStoreContracts.StorageContracts;
|
||||||
using ComputerHardwareStoreDatabaseImplement.Implements;
|
using ComputerHardwareStoreDatabaseImplement.Implements;
|
||||||
using ComputerHardwareStoreREST;
|
using Microsoft.OpenApi.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@ -25,13 +27,36 @@ builder.Services.AddSingleton<ICommentStorage, CommentStorage>();
|
|||||||
builder.Services.AddSingleton<IPurchaseStorage, PurchaseStorage>();
|
builder.Services.AddSingleton<IPurchaseStorage, PurchaseStorage>();
|
||||||
builder.Services.AddSingleton<IVendorStorage, VendorStorage>();
|
builder.Services.AddSingleton<IVendorStorage, VendorStorage>();
|
||||||
|
|
||||||
var app = builder.Build();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
builder.Services.AddTransient<IVendorLogic, VendorLogic>();
|
||||||
|
builder.Services.AddTransient<IProductLogic, ProductLogic>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
|
||||||
|
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
|
builder.Services.AddControllers();
|
||||||
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
|
builder.Services.AddEndpointsApiExplorer();
|
||||||
|
builder.Services.AddSwaggerGen(c =>
|
||||||
|
{
|
||||||
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "AbstractShopRestApi", Version = "v1" });
|
||||||
|
});
|
||||||
|
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())
|
||||||
|
});
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
app.UseSwagger();
|
||||||
app.UseSwaggerUI();
|
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AbstractShopRestApi v1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
|
||||||
|
"SmtpClientHost": "smtp.gmail.com",
|
||||||
|
"SmtpClientPort": "587",
|
||||||
|
"PopHost": "pop.gmail.com",
|
||||||
|
"PopPort": "995",
|
||||||
|
"MailLogin": "coursework@gmail.com",
|
||||||
|
"MailPassword": "123"
|
||||||
|
}
|
67
ComputerHardwareStore/StoreKeeperClient/APIClient.cs
Normal file
67
ComputerHardwareStore/StoreKeeperClient/APIClient.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace StoreKeeperClient
|
||||||
|
{
|
||||||
|
public class APIClient
|
||||||
|
{
|
||||||
|
private static readonly HttpClient _client = new();
|
||||||
|
|
||||||
|
public static StoreKeeperViewModel? StoreKeeper { get; set; } = null;
|
||||||
|
|
||||||
|
public static void Connect(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||||
|
_client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T? GetRequest<T>(string requestUrl)
|
||||||
|
{
|
||||||
|
var response = _client.GetAsync(requestUrl);
|
||||||
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
|
if (response.Result.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PostRequest<T>(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<T, R>(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<R>(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -134,7 +134,16 @@ namespace StoreKeeperClient.Controllers
|
|||||||
Response.Redirect("ReportOnly");
|
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<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||||
public IActionResult Error()
|
public IActionResult Error()
|
||||||
{
|
{
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
@using ComputerHardwareStoreContracts.ViewModels
|
||||||
|
@model List<MessageInfoViewModel>
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Mails";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h1 class="display-4">Заказы</h1>
|
||||||
|
</div>
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
if (Model == null)
|
||||||
|
{
|
||||||
|
<h3 class="display-4">Авторизируйтесь</h3>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Дата письма
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Заголовок
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Текст
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Subject)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Body)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</div>
|
@ -0,0 +1,25 @@
|
|||||||
|
@model ErrorViewModel
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Error";
|
||||||
|
}
|
||||||
|
|
||||||
|
<h1 class="text-danger">Error.</h1>
|
||||||
|
<h2 class="text-danger">An error occurred while processing your request.</h2>
|
||||||
|
|
||||||
|
@if (Model.ShowRequestId)
|
||||||
|
{
|
||||||
|
<p>
|
||||||
|
<strong>Request ID:</strong> <code>@Model.RequestId</code>
|
||||||
|
</p>
|
||||||
|
}
|
||||||
|
|
||||||
|
<h3>Development Mode</h3>
|
||||||
|
<p>
|
||||||
|
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
|
||||||
|
It can result in displaying sensitive information from exceptions to end users.
|
||||||
|
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
|
||||||
|
and restarting the app.
|
||||||
|
</p>
|
@ -0,0 +1,56 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>@ViewData["Title"] - AbstractShowClientApp</title>
|
||||||
|
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
|
<link rel="stylesheet" href="~/css/site.css" />
|
||||||
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||||
|
<div class="container">
|
||||||
|
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Рыбный завод</a>
|
||||||
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||||
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
|
<span class="navbar-toggler-icon"></span>
|
||||||
|
</button>
|
||||||
|
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||||
|
<ul class="navbar-nav flex-grow-1">
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails">Письма</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</header>
|
||||||
|
<div class="container">
|
||||||
|
<main role="main" class="pb-3">
|
||||||
|
@RenderBody()
|
||||||
|
</main>
|
||||||
|
</div>
|
||||||
|
<footer class="border-top footer text-muted">
|
||||||
|
<div class="container">
|
||||||
|
© 2024 - Компьютерный магазин - <a asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||||
|
@RenderSection("Scripts", required: false)
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,5 @@
|
|||||||
|
@*
|
||||||
|
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||||
|
*@
|
||||||
|
@{
|
||||||
|
}
|
@ -0,0 +1,3 @@
|
|||||||
|
@using FishFactoryClientApp
|
||||||
|
@using FishFactoryClientApp.Models
|
||||||
|
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
@ -0,0 +1,3 @@
|
|||||||
|
@{
|
||||||
|
Layout = "_Layout";
|
||||||
|
}
|
67
ComputerHardwareStore/VendorClient/APIClient.cs
Normal file
67
ComputerHardwareStore/VendorClient/APIClient.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using ComputerHardwareStoreContracts.ViewModels;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace VendorClient
|
||||||
|
{
|
||||||
|
public class APIClient
|
||||||
|
{
|
||||||
|
private static readonly HttpClient _client = new();
|
||||||
|
|
||||||
|
public static VendorViewModel? Vendor { get; set; } = null;
|
||||||
|
|
||||||
|
public static void Connect(IConfiguration configuration)
|
||||||
|
{
|
||||||
|
_client.BaseAddress = new Uri(configuration["IPAddress"]);
|
||||||
|
_client.DefaultRequestHeaders.Accept.Clear();
|
||||||
|
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static T? GetRequest<T>(string requestUrl)
|
||||||
|
{
|
||||||
|
var response = _client.GetAsync(requestUrl);
|
||||||
|
var result = response.Result.Content.ReadAsStringAsync().Result;
|
||||||
|
if (response.Result.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject<T>(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new Exception(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PostRequest<T>(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<T, R>(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<R>(result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user