9 Commits

Author SHA1 Message Date
bekodeg
7f1d42b0a6 добавил отчёт в пдф 2024-05-29 16:45:44 +04:00
bekodeg
1314116c20 незнаю 2024-05-29 16:11:57 +04:00
bekodeg
320dc8439c + 2024-05-29 16:11:45 +04:00
bekodeg
735283b20c исправил текст в домене 2024-05-29 16:05:56 +04:00
8aefc24b6a слишком синее неб0.. 2024-05-29 15:47:18 +04:00
598049b063 уладили конфликты 2024-05-29 15:43:40 +04:00
bekodeg
d5fc32850c .jkm b cnhflfybz 2024-05-29 15:26:54 +04:00
bekodeg
7d945a26bc aaaaaaaaaaaaaaaaaaa 2024-05-29 12:38:52 +04:00
46f93270fe работа-работа, перейди на 2024-05-28 15:27:44 +04:00
50 changed files with 1277 additions and 293 deletions

View File

@@ -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();
}
}
}

View File

@@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.19.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>

View File

@@ -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);
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,156 @@
using ComputerHardwareContracts.OfficePackage.HelperModels;
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums;
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml.EMMA;
using MigraDoc.Rendering;
namespace ComputerHardwareContracts.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void GetPurchaseReportFile(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph
{
Text = info.Title,
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateParagraph(new PdfParagraph
{
Text = $"за период с {info.DateFrom.ToShortDateString()} " +
$"по {info.DateTo.ToShortDateString()}",
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
CreateTable(new List<string> { "3cm", "4cm", "3cm", "4cm", "4cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Покупка", "Дата покупки", "Цена", "Комментарии", "Комплектующие" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var record in info.ReportPurchases)
{
List<string> comments = record.Comments;
List<string> components = record.Components;
int recordHeight = Math.Max(comments.Count + 1, components.Count + 1);
for (int i = 0; i < recordHeight; i++)
{
List<string> cellsData = new() { "", "", "", "", "" };
if (i == 0)
{
cellsData[0] = record.Id.ToString();
cellsData[1] = record.PurchaseDate.ToShortDateString();
cellsData[2] = record.PurchaseSum.ToString("0.00") + " р.";
CreateRow(new PdfRowParameters
{
Texts = cellsData,
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
continue;
}
int k = i - 1;
if (k < comments.Count)
{
cellsData[3] = comments[k];
}
if (k < components.Count)
{
cellsData[4] = components[k];
}
CreateRow(new PdfRowParameters
{
Texts = cellsData,
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
CreateParagraph(new PdfParagraph { Text = $"Итого: {info.ReportPurchases.Sum(x => x.PurchaseSum)}\t", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Left });
SavePdf(info);
}
public void CreateComponentsReport(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "5cm", "5cm", "3cm" });
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Комплектующее", "Товар/Сборка", "Количество" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var record in info.ReportComponents)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { record.ComponentName, "", "" },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach (var goodOrBuild in record.GoodOrBuilds)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", goodOrBuild.Item1, goodOrBuild.Item2.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Итого", "", record.TotalCount.ToString() },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
SavePdf(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreatePdf(PdfInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@@ -0,0 +1,11 @@
namespace ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Rigth
}
}

View File

@@ -0,0 +1,19 @@
using ComputerHardwareContracts.ViewModels;
namespace ComputerHardwareContracts.OfficePackage.HelperModels
{
public class PdfInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportComponentsViewModel> ReportComponents { get; set; } = new();
public List<ReportPurchaseViewModel> ReportPurchases { get; set; } = new();
}
}

View File

@@ -0,0 +1,13 @@
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums;
namespace ComputerHardwareStoreBusinessLogic.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums;
namespace ComputerHardwareStoreBusinessLogic.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@@ -0,0 +1,117 @@
using ComputerHardwareContracts.OfficePackage;
using ComputerHardwareContracts.OfficePackage.HelperModels;
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums;
using ComputerHardwareStoreBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace ComputerHardwareStoreBusinessLogic.OfficePackage.Implements
{
public class SaveToPdf : AbstractSaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Rigth => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@@ -7,7 +7,7 @@ namespace ComputerHardwareStoreContracts.BindingModels
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
public double Price { get; set; }
public IVendorModel Vendor { get; set; }
public int VendorId { get; set; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
public List<ICommentModel> Comments { get; set; } = new();
}

View File

@@ -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; }
}
}

View File

@@ -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>();
}
}

View File

@@ -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; }
}
}

View File

@@ -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);
}
}

View File

@@ -6,6 +6,10 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputerHardwareStoreDataModels\ComputerHardwareStoreDataModels.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,8 @@
namespace ComputerHardwareStoreContracts.SearchModels
{
public class MessageInfoSearchModel
{
public int? ClientId { get; set; }
public string? MessageId { get; set; }
}
}

View File

@@ -4,5 +4,6 @@
{
public int? Id { get; set; }
public string? Login { get; set; }
}
public string? Password { get; set; }
}
}

View File

@@ -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);
}
}

View File

@@ -10,8 +10,9 @@ namespace ComputerHardwareStoreContracts.ViewModels
public string Name { get; set; } = string.Empty;
[DisplayName("Стоимость")]
public double Price { get; set; }
public IVendorModel Vendor { get; set; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; set; } = new();
public List<ICommentModel> Comments { get; set; } = new();
public int VendorId { get; set; }
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,11 @@
namespace ComputerHardwareContracts.ViewModels
{
public class ReportComponentsViewModel
{
public string ComponentName { get; set; } = string.Empty;
public int TotalCount { get; set; }
public List<Tuple<string, int>> GoodOrBuilds { get; set; } = new();
}
}

View File

@@ -0,0 +1,15 @@
namespace HardwareShopContracts.ViewModels
{
public class ReportPurchaseComponentViewModel
{
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; }
}
}

View File

@@ -0,0 +1,15 @@
namespace ComputerHardwareContracts.ViewModels
{
public class ReportPurchaseViewModel
{
public int Id { get; set; }
public DateTime PurchaseDate { get; set; }
public double PurchaseSum { get; set; }
public List<string> Comments { get; set; } = new();
public List<string> Components { get; set; } = new();
}
}

View File

@@ -4,7 +4,7 @@
{
string Name { get; }
double Price { get; }
IVendorModel Vendor { get; }
public int VendorId { get; }
public Dictionary<int, (IComponentModel, int)> BuildComponents { get; }
public List<ICommentModel> Comments { get; }
}

View File

@@ -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; }
}
}

View File

@@ -93,7 +93,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.Where(b => b.Vendor.Id == model.VendorId)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{
@@ -111,7 +111,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Implements
.Include(b => b.Components)
.ThenInclude(b => b.Component)
.Include(b => b.Vendor)
.Where(b => b.Vendor.Id == model.Vendor.Id)
.Where(b => b.Vendor.Id == model.VendorId)
.FirstOrDefault(p => p.Id == model.Id);
if (build == null)
{

View File

@@ -14,6 +14,8 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
public string Name { get; set; } = string.Empty;
[Required]
public double Price { get; set; }
public int VendorId { get; set; }
[NotMapped]
private Dictionary<int, (IComponentModel, int)>? _buildComponents = null;
[NotMapped]
@@ -39,7 +41,6 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
List<ICommentModel> IBuildModel.Comments => Comments.Select(c => c as ICommentModel).ToList();
public virtual Vendor Vendor { get; private set; } = new();
IVendorModel IBuildModel.Vendor => Vendor as IVendorModel;
public static Build? Create(ComputerHardwareStoreDBContext context, BuildBindingModel model)
{
@@ -52,7 +53,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Price = model.Price,
Vendor = context.Vendors.First(v => v.Id == model.Vendor.Id),
VendorId = model.VendorId,
Components = context.Components
.Where(c => model.BuildComponents.ContainsKey(c.Id))
.Select(c => new BuildComponent()
@@ -80,7 +81,7 @@ namespace ComputerHardwareStoreDatabaseImplement.Models
Id = Id,
Name = Name,
Price = Price,
Vendor = Vendor,
VendorId = VendorId,
Comments = Comments.Select(c => c as ICommentModel).ToList(),
BuildComponents = BuildComponents
};

View File

@@ -22,6 +22,7 @@
<ItemGroup>
<ProjectReference Include="..\ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj" />
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
</ItemGroup>

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using System.Globalization;
namespace ComputerHardwareStoreREST.Controllers
{
public class ReportsController : Controller
{
public IActionResult Index()
{
return View();
}
}
}

View File

@@ -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<StoreKeepersController> _logger;
private readonly IStoreKeeperStorage _storage;
public StoreKeepersController(ILogger<StoreKeepersController> 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<StoreKeeperController> 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<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения писем клиента");
throw;
}
}
}
}

View File

@@ -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<VendorController> _logger;
private readonly IVendorStorage _storage;
public VendorController(ILogger<VendorController> 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<VendorController> 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<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения писем клиента");
throw;
}
}
}
}

View File

@@ -1,7 +1,7 @@
using ComputerHardwareStoreBusinessLogic.BusinessLogic;
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.BusinessLogicsContracts;
using ComputerHardwareStoreContracts.StorageContracts;
using ComputerHardwareStoreDatabaseImplement;
using ComputerHardwareStoreDatabaseImplement.Implements;
using ComputerHardwareStoreREST;
using Microsoft.EntityFrameworkCore;
@@ -36,12 +36,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.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "AbstractShopRestApi v1"));
}
app.UseHttpsRedirection();

View File

@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

View File

@@ -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"
}

View File

@@ -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;
}
}
}
}

View File

@@ -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<List<MessageInfoViewModel>>($"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 });

View File

@@ -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>

View File

@@ -0,0 +1,5 @@
@*
For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
}

View File

@@ -22,4 +22,4 @@
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>
</p>

View File

@@ -1,34 +1,34 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - ComputerStoreWorkerApp</title>
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
<link rel="stylesheet" href="~/ComputerStoreWorkerApp.styles.css" asp-append-version="true" />
</head>
<body>
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<header>
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
<div class="container-fluid">
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">ComputerStoreWorkerApp</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
<ul class="navbar-nav flex-grow-1">
<li class="nav-item">
<ul class="navbar-nav flex-grow-1">
<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="Components">Комплектующие</a>
</li>
<li class="nav-item">
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Products">Товары</a>
</li>
<li class="nav-item">
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Orders">Заказы на товары</a>
</li>
<li class="nav-item">
@@ -36,32 +36,32 @@
</li>
<li class="nav-item">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ComponentsByPurchasesAndOrdersReport">Отчёт по комплектующим за период</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>
</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">
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2024 - ComputerStoreWorkerApp - <a asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
</div>
</footer>
</div>
</footer>
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/site.js" asp-append-version="true"></script>
@await RenderSectionAsync("Scripts", required: false)
</body>
</html>
</html>

View File

@@ -1,3 +1,3 @@
@using StoreKeeperClient
@using StoreKeeperClient.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

View File

@@ -1,3 +1,3 @@
@{
Layout = "_Layout";
}
}

View File

@@ -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;
}
}
}
}

View File

@@ -0,0 +1,96 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Xml.Linq;
namespace VendorClient.Controllers
{
[Route("Home/[action]")]
public class BuildController : Controller
{
private readonly ILogger _logger;
private const string API_ROUTE = "api/builds";
public BuildController(ILogger<BuildController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult AddBuildToPurchase()
{
return View();
}
[HttpGet]
public IActionResult Builds()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.GetRequest<List<BuildViewModel>>($"{API_ROUTE}/getbuilds?userId={APIClient.Vendor.Id}"));
}
[HttpGet]
public void BuildCreate(string buildName)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(buildName))
{
throw new Exception($"Имя сборки не должно быть пустым");
}
APIClient.PostRequest($"{API_ROUTE}/create", new BuildBindingModel
{
Name = buildName,
VendorId = APIClient.Vendor.Id
});
Response.Redirect("~/Home/Builds");
}
[HttpGet]
public void BuildDelete(int id)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (id <= 0)
{
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
}
APIClient.PostRequest("api/build/DeleteBuild", new BuildBindingModel
{
Id = id
});
Response.Redirect("~/Home/Builds");
}
[HttpGet]
public void BuildUpdate(string buildName, int buildId)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
}
if (string.IsNullOrEmpty(buildName))
{
throw new Exception($"Имя сборки не должно быть пустым");
}
if (buildId <= 0)
{
throw new Exception($"Идентификатор сборки не может быть ниже или равен 0");
}
APIClient.PostRequest($"{API_ROUTE}/update", new BuildBindingModel
{
Id = buildId,
Name = buildName
});
Response.Redirect("~/Home/Builds");
}
}
}

View File

@@ -1,10 +1,12 @@
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using VendorClient.Models;
namespace VendorClient.Controllers
{
[Route("Home/[action]")]
public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;
@@ -17,56 +19,56 @@ namespace VendorClient.Controllers
[HttpGet]
public IActionResult Index()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpGet]
public IActionResult Privacy()
{
return View();
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
return View(APIClient.Vendor);
}
[HttpGet]
public IActionResult Enter()
public void Enter(string email, string password)
{
return View();
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
{
throw new Exception("Введите почту и пароль");
}
APIClient.Vendor = APIClient.GetRequest<VendorViewModel>($"api/vendor/login?email={email}&password={password}");
if (APIClient.Vendor == null)
{
throw new Exception("Неверные почта и/или пароль");
}
Response.Redirect("MainWorker");
}
[HttpGet]
public IActionResult Register()
public void Register(string email, string password, string fio)
{
return View();
}
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{
throw new Exception("Введите логин, пароль и ФИО");
}
APIClient.PostRequest("api/pharmacist/register", new VendorBindingModel
{
Name = fio,
Login = email,
Password = password
});
Response.Redirect("~/Home/Enter");
return;
}
[HttpGet]
public IActionResult AddBuildToPurchase()
{
return View();
}
[HttpGet]
public IActionResult Builds()
{
return View(new List<BuildViewModel>());
}
[HttpGet]
public IActionResult BuildCreate()
{
return View();
}
[HttpGet]
public IActionResult BuildDelete()
{
return View();
}
[HttpGet]
public IActionResult BuildUpdate()
{
return View();
}
[HttpGet]
public IActionResult CommentCreate()
@@ -92,47 +94,6 @@ namespace VendorClient.Controllers
return View(new List<CommentViewModel>());
}
[HttpGet]
public IActionResult ProductsList()
{
return View(new List<BuildViewModel>());
}
[HttpGet]
public IActionResult PurchaseCreate()
{
return View();
}
[HttpGet]
public IActionResult PurchaseDelete()
{
return View();
}
[HttpGet]
public IActionResult Purchases()
{
return View(new List<PurchaseViewModel>());
}
[HttpGet]
public IActionResult PurchaseUpdate()
{
return View();
}
[HttpGet]
public IActionResult Report()
{
return View(new List<PurchaseViewModel>());
}
[HttpPost]
public void Report(string password)
{
Response.Redirect("ReportOnly");
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()

View File

@@ -0,0 +1,99 @@
using ComputerHardwareStoreContracts.BindingModels;
using ComputerHardwareStoreContracts.SearchModels;
using ComputerHardwareStoreContracts.ViewModels;
using ComputerHardwareStoreDataModels.Models;
using Microsoft.AspNetCore.Mvc;
namespace VendorClient.Controllers
{
[Route("Home/[action]")]
public class PurchaseController : Controller
{
private readonly ILogger<PurchaseController> _logger;
private const string API_ROUTE = "api/purchases";
public PurchaseController(ILogger<PurchaseController> logger)
{
_logger = logger;
}
[HttpGet]
public IActionResult Products()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Enter");
}
ViewBag.Goods = APIClient.GetRequest<List<ProductViewModel>>($"api/products/GetAllProducts");
return View();
}
[HttpPost]
public void PurchaseCreate([FromBody] PurchaseBindingModel purchaseModel)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (purchaseModel.Cost <= 0)
{
throw new Exception("Цена должна быть больше 0");
}
purchaseModel.VendorId = APIClient.Vendor.Id;
APIClient.PostRequest($"{API_ROUTE}/createpurchase", purchaseModel);
}
[HttpGet]
public void PurchaseDelete(int id)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
if (id <= 0)
{
throw new Exception("Некорректный идентификатор");
}
var purchase = APIClient.GetRequest<PurchaseViewModel>($"api/purchase/getpurchase?purchaseId={id}");
APIClient.PostRequest($"{API_ROUTE}/DeletePurchase", new PurchaseBindingModel
{
Id = id,
});
}
[HttpGet]
public IActionResult Purchases()
{
if (APIClient.Vendor == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Purchases = APIClient.PostRequestWithResult<PurchaseSearchModel, List<PurchaseViewModel>>(
$"{API_ROUTE}/getpurchases", new() { VendorId = APIClient.Vendor.Id });
return View();
}
[HttpGet]
public void PurchaseUpdate([FromBody] PurchaseBindingModel purchaseModel)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
purchaseModel.VendorId = APIClient.Vendor.Id;
APIClient.PostRequest("api/purchase/update", purchaseModel);
}
[HttpGet]
public string Report(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.Vendor == null)
{
throw new Exception("Вы как сюда попали? Сюда вход только авторизованным");
}
return "NotImplement";
}
}
}

View File

@@ -0,0 +1,65 @@
@{
ViewData["Title"] = "Report";
}
<div class="container">
<div class="text-center mb-4">
<h2 class="text-custom-color-1">отчёт по покупкам за период</h2>
</div>
<form method="post">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="dateFrom" class="form-label text-custom-color-1">Начало периода:</label>
<input type="datetime-local" id="dateFrom" name="dateFrom" class="form-control" placeholder="Выберите дату начала периода">
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label for="dateTo" class="form-label text-custom-color-1">Окончание периода:</label>
<input type="datetime-local" id="dateTo" name="dateTo" class="form-control" placeholder="Выберите дату окончания периода">
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="submit" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Отправить на почту</button>
</div>
</div>
<div class="row mb-4">
<div class="col-md-8"></div>
<div class="col-md-4">
<button type="button" id="demonstrate" class="btn btn-outline-dark w-100 text-center d-flex justify-content-md-center">Продемонстрировать</button>
</div>
</div>
<div id="report"></div>
</form>
</div>
@section Scripts {
<script>
function check() {
var dateFrom = $('#dateFrom').val();
var dateTo = $('#dateTo').val();
if (dateFrom && dateTo) {
$.ajax({
method: "GET",
url: "/GetPurchaseReport",
data: { dateFrom: dateFrom, dateTo: dateTo },
success: function (result) {
if (result != null) {
$('#report').html(result);
}
}
});
};
}
check();
$('#demonstrate').on('click', (e) => check());
</script>
}

View File

@@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
namespace VendorClient.Views.Home
{
public class ReportModel : PageModel
{
public void OnGet()
{
}
}
}

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>@ViewData["Title"] - AutomobilePlantClientApp</title>
<title>@ViewData["Title"] - Тыж Программист</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>