pdf fix
This commit is contained in:
parent
6ce5987034
commit
3a17c1bb9e
@ -43,7 +43,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
|
||||
if (model == null) {
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation($"ReadElement.Login:{model.Login}.ID:{model.ID}");
|
||||
_logger.LogInformation($"ReadElement.Email:{model.Login}.ID:{model.ID}");
|
||||
var element = _storage.GetElement(model);
|
||||
if (element == null) {
|
||||
_logger.LogWarning("ReadElement. element not fount");
|
||||
@ -79,8 +79,8 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
|
||||
if (!withParams) {
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.Login)) {
|
||||
throw new ArgumentNullException("Нет логина сотрудника", nameof(model.Login));
|
||||
if (string.IsNullOrEmpty(model.Email)) {
|
||||
throw new ArgumentNullException("Нет логина сотрудника", nameof(model.Email));
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.EmployeeFIO)) {
|
||||
throw new ArgumentNullException("Нет ФИО сотрудника", nameof(model.EmployeeFIO));
|
||||
@ -88,10 +88,10 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic {
|
||||
if (string.IsNullOrEmpty(model.Password)) {
|
||||
throw new ArgumentNullException("Нет пароля сотрудника", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.EmployeeFIO}.Password:{model.Password}.Email:{model.Login}.");
|
||||
_logger.LogInformation($"Client. ID:{model.ID}.ClientFIO:{model.EmployeeFIO}.Password:{model.Password}.Email:{model.Email}.");
|
||||
|
||||
var element = _storage.GetElement(new EmployeeSearchModel {
|
||||
Login = model.Login
|
||||
Login = model.Email
|
||||
});
|
||||
if (element != null && element.ID != model.ID) {
|
||||
throw new InvalidOperationException("Сотрудник с таким логином уже есть");
|
||||
|
@ -6,6 +6,7 @@ using ElectronicsShopContracts.BusinessLogicContracts;
|
||||
using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.StorageContracts;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -93,7 +94,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
return document;
|
||||
}
|
||||
|
||||
public byte[]? SaveProductsToPdfFile(ReportProductBindingModel model) {
|
||||
public PdfDocument SaveProductsToPdfFile(ReportProductBindingModel model) {
|
||||
var document = _saveToPdf.CreateDoc(new PdfInfoEmployee {
|
||||
Title = "Список оплат электротоваров",
|
||||
DateFrom = model.DateFrom,
|
||||
@ -102,10 +103,7 @@ namespace ElectronicsShopBusinessLogic.BusinessLogic
|
||||
FileName = "Report"
|
||||
});
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
document.Save(stream, true);
|
||||
byte[] data = stream.ToArray();
|
||||
return data;
|
||||
return document;
|
||||
}
|
||||
|
||||
public byte[]? SaveProductsToWordFile(ReportProductBindingModel model)
|
||||
|
@ -11,7 +11,7 @@ namespace ElectronicsShopContracts.BindingModels {
|
||||
|
||||
public string EmployeeFIO { get; set; } = string.Empty;
|
||||
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
public string Password { get; set; } = string.Empty;
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
using PdfSharp.Pdf;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -13,6 +14,6 @@ namespace ElectronicsShopContracts.BusinessLogicContracts
|
||||
List<ReportProductInPaymeantsViewModel> GetProducts(ReportProductBindingModel model);
|
||||
byte[]? SaveProductsToWordFile(ReportProductBindingModel model);
|
||||
byte[]? SaveProductsToExcelFile(ReportProductBindingModel model);
|
||||
byte[]? SaveProductsToPdfFile(ReportProductBindingModel model);
|
||||
PdfDocument SaveProductsToPdfFile(ReportProductBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace ElectronicsShopContracts.ViewModels
|
||||
public string EmployeeFIO { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Логина сотрудника")]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Пароль сотрудника")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
@ -12,7 +12,7 @@ namespace ElectronicsShopDataBaseImplement
|
||||
optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false) {
|
||||
optionsBuilder.UseSqlServer(@"Data Source=WIN-S7AOPVO8GAA\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
optionsBuilder.UseSqlServer(@"Data Source=WIN-4HUIDGH3G02\SQLEXPRESS;Initial Catalog=ElectronicsShopDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
@ -54,18 +54,18 @@ namespace ElectronicsShopDataBaseImplement.Implements
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(model.Login) && !string.IsNullOrEmpty(model.Password)) {
|
||||
return context.Employees
|
||||
.FirstOrDefault(x => (x.Login == model.Login && x.Password == model.Password))
|
||||
.FirstOrDefault(x => (x.Email == model.Login && x.Password == model.Password))
|
||||
?.GetViewModel;
|
||||
}
|
||||
return context.Employees
|
||||
.FirstOrDefault(x => (x.Login == model.Login))
|
||||
.FirstOrDefault(x => (x.Email == model.Login))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
||||
{
|
||||
using var context = new Database();
|
||||
return context.Employees.Where(x => x.Login
|
||||
return context.Employees.Where(x => x.Email
|
||||
.Contains(model.Login))
|
||||
.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
|
@ -90,7 +90,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
|
@ -87,7 +87,7 @@ namespace ElectronicsShopDataBaseImplement.Migrations
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<string>("Login")
|
||||
b.Property<string>("Email")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
public string EmployeeFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Login { get; set; } = string.Empty;
|
||||
public string Email { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
@ -35,7 +35,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
{
|
||||
ID = model.ID,
|
||||
EmployeeFIO = model.EmployeeFIO,
|
||||
Login = model.Login,
|
||||
Email = model.Email,
|
||||
Password = model.Password,
|
||||
};
|
||||
}
|
||||
@ -46,7 +46,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
return;
|
||||
}
|
||||
EmployeeFIO = model.EmployeeFIO;
|
||||
Login = model.Login;
|
||||
Email = model.Email;
|
||||
Password = model.Password;
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ namespace ElectronicsShopDataBaseImplement.Models
|
||||
{
|
||||
ID = ID,
|
||||
EmployeeFIO = EmployeeFIO,
|
||||
Login = Login,
|
||||
Email = Email,
|
||||
Password = Password,
|
||||
};
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
||||
namespace ElectronicsShopDataModels.Models {
|
||||
public interface IEmployeeModel : IID {
|
||||
string EmployeeFIO { get; }
|
||||
string Login { get; }
|
||||
string Email { get; }
|
||||
string Password { get; }
|
||||
}
|
||||
}
|
||||
|
@ -48,12 +48,12 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
APIEmployee.PostRequest("api/employee/updatedata", new EmployeeBindingModel {
|
||||
ID = APIEmployee.Employee.ID,
|
||||
EmployeeFIO = fio,
|
||||
Login = login,
|
||||
Email = login,
|
||||
Password = password,
|
||||
});
|
||||
|
||||
APIEmployee.Employee.EmployeeFIO = fio;
|
||||
APIEmployee.Employee.Login = login;
|
||||
APIEmployee.Employee.Email = login;
|
||||
APIEmployee.Employee.Password = password;
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
@ -92,7 +92,7 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
}
|
||||
APIEmployee.PostRequest("api/employee/register", new EmployeeBindingModel {
|
||||
EmployeeFIO = fio,
|
||||
Login = login,
|
||||
Email = login,
|
||||
Password = password
|
||||
});
|
||||
Response.Redirect("Enter");
|
||||
@ -366,13 +366,13 @@ namespace ElectronicsShopEmployeeApp.Controllers {
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult CreatePdfReport(string DateFrom, string DateTo) {
|
||||
var fileMemStream = APIEmployee.GetRequset<byte[]>($"api/Employee/CreatePdfReport?from={DateFrom}&to={DateTo}");
|
||||
|
||||
if (fileMemStream == null) {
|
||||
throw new Exception("Îøèáêà ñîçäàíèÿ îò÷åòà");
|
||||
}
|
||||
|
||||
return File(fileMemStream, "application/pdf", "Report.pdf");
|
||||
APIEmployee.PostRequest("api/Employee/SendReportMail", new ReportBindingModel {
|
||||
ClientEmail = APIEmployee.Employee?.Email ?? throw new Exception("Îøèáêà ïîëó÷åíèÿ àäðåñà"),
|
||||
DateFrom = DateTime.Parse(DateFrom),
|
||||
DateTo = DateTime.Parse(DateTo),
|
||||
ClientID = APIEmployee.Employee.ID
|
||||
});
|
||||
return View("Report");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Логин:</div>
|
||||
<div class="col-8"><input type="text" name="login" value="@Model.Login" /></div>
|
||||
<div class="col-8"><input type="text" name="login" value="@Model.Email" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Пароль:</div>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopBusinessLogic.MailWorker;
|
||||
using ElectronicsShopContracts.BindingModels;
|
||||
using ElectronicsShopContracts.BusinessLogicContracts;
|
||||
using ElectronicsShopContracts.SearchModels;
|
||||
using ElectronicsShopContracts.ViewModels;
|
||||
@ -17,14 +18,16 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
private readonly ICostItemLogic _costItem;
|
||||
private readonly IProductLogic _productLogic;
|
||||
private readonly IReportEmployeeLogic _reportEmployeeLogic;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
|
||||
public EmployeeController(ILogger<EmployeeController> logger, IEmployeeLogic logic, ICostItemLogic costItem, IProductLogic productLogic,
|
||||
IReportEmployeeLogic reportEmployeeLogic) {
|
||||
IReportEmployeeLogic reportEmployeeLogic, AbstractMailWorker mailWorker) {
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
_costItem = costItem;
|
||||
_productLogic = productLogic;
|
||||
_reportEmployeeLogic = reportEmployeeLogic;
|
||||
_mailWorker = mailWorker;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@ -181,14 +184,25 @@ namespace ElectronicsShopRestAPI.Controllers {
|
||||
}
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public byte[]? CreatePdfReport(string from, string to) {
|
||||
[HttpPost]
|
||||
public void SendReportMail(ReportBindingModel model) {
|
||||
try {
|
||||
var document = _reportEmployeeLogic.SaveProductsToPdfFile(new ReportProductBindingModel {
|
||||
DateFrom = DateTime.Parse(from),
|
||||
DateTo = DateTime.Parse(to)
|
||||
DateFrom = model.DateFrom,
|
||||
DateTo = model.DateTo,
|
||||
});
|
||||
return document;
|
||||
|
||||
MemoryStream stream = new MemoryStream();
|
||||
document.Save(stream, true);
|
||||
byte[] data = stream.ToArray();
|
||||
|
||||
_mailWorker.MailSendAsync(new() {
|
||||
MailAddress = model.ClientEmail,
|
||||
Subject = "Отчет",
|
||||
Text = $"Отчет по товарам с указанием оплат с {model.DateFrom.ToShortDateString()} по {model.DateTo.ToShortDateString()}",
|
||||
document = data
|
||||
});
|
||||
|
||||
}
|
||||
catch (Exception ex) {
|
||||
_logger.LogError(ex, "Ошибка создания файла");
|
||||
|
@ -79,7 +79,7 @@ namespace ElectronicsShopUserApp.Controllers {
|
||||
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) {
|
||||
throw new Exception("Ââåäèòå ïî÷òó è ïàðîëü");
|
||||
}
|
||||
APIClient.Client = APIClient.GetRequset<ClientViewModel>($"api/Client/Login?email={email}&password={password}");
|
||||
APIClient.Client = APIClient.GetRequset<ClientViewModel>($"api/Client/Email?email={email}&password={password}");
|
||||
if (APIClient.Client == null) {
|
||||
throw new Exception("Íåâåðíûé àäðåñ ïî÷òû/ïàðîëü");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user