уладили конфликты
This commit is contained in:
commit
598049b063
@ -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
|
||||
|
@ -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>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MailKit" Version="4.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
|
||||
</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 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; }
|
||||
}
|
||||
}
|
@ -2,87 +2,82 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class StoreKeepersController : Controller
|
||||
public class StoreKeeperController : Controller
|
||||
{
|
||||
private readonly ILogger<StoreKeepersController> _logger;
|
||||
private readonly IStoreKeeperStorage _storage;
|
||||
|
||||
public StoreKeepersController(ILogger<StoreKeepersController> logger, IStoreKeeperStorage storage)
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreKeeperLogic _logic;
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public StoreKeeperController(IStoreKeeperLogic logic, IMessageInfoLogic mailLogic, ILogger<StoreKeeperController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
_logic = logic;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] StoreKeeperSearchModel model)
|
||||
[HttpGet]
|
||||
public StoreKeeperViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
return _logic.ReadElement(new StoreKeeperSearchModel
|
||||
{
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] StoreKeeperSearchModel model)
|
||||
[HttpPost]
|
||||
public void Register(StoreKeeperBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] StoreKeeperBindingModel model)
|
||||
[HttpPost]
|
||||
public void UpdateData(StoreKeeperBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] StoreKeeperBindingModel model)
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,86 +1,81 @@
|
||||
using ComputerHardwareStoreContracts.BindingModels;
|
||||
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
|
||||
using ComputerHardwareStoreContracts.SearchModels;
|
||||
using ComputerHardwareStoreContracts.StorageContracts;
|
||||
using ComputerHardwareStoreContracts.ViewModels;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
[Route("api/[controller]/[action]")]
|
||||
[ApiController]
|
||||
[Route("[controller]")]
|
||||
public class VendorController : Controller
|
||||
{
|
||||
private readonly ILogger<VendorController> _logger;
|
||||
private readonly IVendorStorage _storage;
|
||||
|
||||
public VendorController(ILogger<VendorController> logger, IVendorStorage storage)
|
||||
private readonly ILogger _logger;
|
||||
private readonly IVendorLogic _logic;
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public VendorController(IVendorLogic logic, IMessageInfoLogic mailLogic, ILogger<VendorController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_storage = storage;
|
||||
_logic = logic;
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
|
||||
[HttpPost("get/filter")]
|
||||
public IActionResult GetByFilter([FromBody] VendorSearchModel model)
|
||||
[HttpGet]
|
||||
public VendorViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetFilteredList(model);
|
||||
return Ok(result);
|
||||
return _logic.ReadElement(new VendorSearchModel
|
||||
{
|
||||
Login = login,
|
||||
Password = password
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка входа в систему");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost("get")]
|
||||
public IActionResult GetById([FromBody] VendorSearchModel model)
|
||||
[HttpPost]
|
||||
public void Register(VendorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.GetElement(model);
|
||||
return Ok(result);
|
||||
_logic.Create(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка регистрации");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost("create")]
|
||||
public IActionResult Create([FromBody] VendorBindingModel model)
|
||||
[HttpPost]
|
||||
public void UpdateData(VendorBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Insert(model);
|
||||
return Ok(result);
|
||||
_logic.Update(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return BadRequest(ex.Message);
|
||||
_logger.LogError(ex, "Ошибка обновления данных");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPut("update")]
|
||||
public IActionResult Update([FromBody] VendorBindingModel model)
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = _storage.Update(model);
|
||||
return Ok(result);
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
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);
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<IStoreKeeperLogic, StoreKeeperLogic>();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
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.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AbstractShopRestApi v1"));
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"SmtpClientHost": "smtp.gmail.com",
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
"MailLogin": "coursework@gmail.com",
|
||||
"MailPassword": "123"
|
||||
}
|
@ -15,6 +15,7 @@ namespace StoreKeeperClient
|
||||
_client.DefaultRequestHeaders.Accept.Clear();
|
||||
_client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
}
|
||||
|
||||
public static T? GetRequest<T>(string requestUrl)
|
||||
{
|
||||
var response = _client.GetAsync(requestUrl);
|
||||
@ -28,16 +29,37 @@ namespace StoreKeeperClient
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -233,6 +233,15 @@ namespace StoreKeeperClient.Controllers
|
||||
Response.Redirect("ReportOnly");
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
|
@ -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>
|
@ -5,16 +5,19 @@ using System.Text;
|
||||
|
||||
namespace VendorClient
|
||||
{
|
||||
public static class APIClient
|
||||
public class APIClient
|
||||
{
|
||||
private static readonly HttpClient _client = new();
|
||||
public static StoreKeeperViewModel? Client { get; set; } = null;
|
||||
|
||||
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);
|
||||
@ -28,16 +31,37 @@ namespace VendorClient
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user