Compare commits
6 Commits
BACKDEV-41
...
BACKDEV-41
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f1d42b0a6 | ||
|
|
1314116c20 | ||
|
|
320dc8439c | ||
|
|
735283b20c | ||
|
|
d5fc32850c | ||
|
|
7d945a26bc |
@@ -14,9 +14,6 @@ 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
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace ComputerHardwareStoreBusinessLogic.OfficePackage.HelperEnums
|
||||
{
|
||||
public enum PdfParagraphAlignmentType
|
||||
{
|
||||
Center,
|
||||
|
||||
Left,
|
||||
|
||||
Rigth
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,15 @@
|
||||
namespace ComputerHardwareStoreContracts.ViewModels
|
||||
namespace ComputerHardwareContracts.ViewModels
|
||||
{
|
||||
public class ReportPurchaseViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public class ReportPurchaseViewModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public List<(string Build, int count, List<(string Component, int count)>)> Builds { get; set; } = new();
|
||||
public DateTime PurchaseDate { get; set; }
|
||||
|
||||
public int TotalCount { get; set; }
|
||||
public double PurchaseSum { get; set; }
|
||||
|
||||
public double TotalCost { get; set; }
|
||||
}
|
||||
public List<string> Comments { get; set; } = new();
|
||||
|
||||
public List<string> Components { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ComputerHardwareStoreBusinessLogic\ComputerHardwareStoreBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\ComputerHardwareStoreContracts\ComputerHardwareStoreContracts.csproj" />
|
||||
<ProjectReference Include="..\ComputerHardwareStoreDatabaseImplement\ComputerHardwareStoreDatabaseImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Globalization;
|
||||
|
||||
namespace ComputerHardwareStoreREST.Controllers
|
||||
{
|
||||
public class ReportsController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
}
|
||||
65
ComputerHardwareStore/VendorClient/Views/Home/Report.cshtml
Normal file
65
ComputerHardwareStore/VendorClient/Views/Home/Report.cshtml
Normal 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>
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace VendorClient.Views.Home
|
||||
{
|
||||
public class ReportModel : PageModel
|
||||
{
|
||||
public void OnGet()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user