Вывод сообщений аунтефикации у "Заказчика"

This commit is contained in:
abazov73 2023-05-20 00:24:41 +04:00
parent 85c1a88c19
commit e60309c7dd

View File

@ -48,7 +48,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
return Redirect("~/Home/Enter"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
} }
return View(APIClient.Operator); return View(APIClient.Operator);
} }
@ -58,7 +59,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return;
} }
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName)) if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(lastname) || string.IsNullOrEmpty(firstname) || string.IsNullOrEmpty(middleName))
{ {
@ -136,6 +138,11 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult CreateDeal() public IActionResult CreateDeal()
{ {
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
}
return View(); return View();
} }
@ -144,7 +151,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return;
} }
_dealLogic.Create(new DealBindingModel _dealLogic.Create(new DealBindingModel
{ {
@ -157,13 +165,19 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
return Redirect("~/Home/Enter"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
} }
return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id })); return View(_paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }));
} }
[HttpGet] [HttpGet]
public IActionResult CreatePayment() public IActionResult CreatePayment()
{ {
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
}
ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id }); ViewBag.Deals = _dealLogic.ReadList(new DealSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
} }
@ -172,7 +186,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return;
} }
Dictionary<int, IDealModel> DealPayments = new(); Dictionary<int, IDealModel> DealPayments = new();
foreach (int id in deals) foreach (int id in deals)
@ -186,6 +201,11 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Payment(int id) public IActionResult Payment(int id)
{ {
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
}
return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id })); return View(_paymentLogic.ReadElement(new PaymentSearchModel { Id = id }));
} }
[HttpGet] [HttpGet]
@ -193,7 +213,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
} }
return View(_transferLogic.ReadList(new TransferSearchModel { OperatorId = APIClient.Operator.Id })); return View(_transferLogic.ReadList(new TransferSearchModel { OperatorId = APIClient.Operator.Id }));
} }
@ -202,7 +223,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
} }
ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }); ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
@ -212,7 +234,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return;
} }
_transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment }); _transferLogic.Create(new TransferBindingModel { OperatorId = APIClient.Operator.Id, Amount = (float)Convert.ToDouble(amount), PaymentId = payment });
@ -222,7 +245,7 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
} }
_transferLogic.Delete(new TransferBindingModel { Id = id }); _transferLogic.Delete(new TransferBindingModel { Id = id });
Response.Redirect("/Home/Transfers"); Response.Redirect("/Home/Transfers");
@ -233,8 +256,8 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');</script>"); Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
Response.Redirect("/Home/Enter"); return Redirect("/Home/Enter");
} }
ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }); ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
@ -271,23 +294,34 @@ namespace OperatorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult TransfersReport() public IActionResult TransfersReport()
{ {
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return Redirect("/Home/Enter");
}
return View(new ReportBindingModel()); return View(new ReportBindingModel());
} }
[HttpPost] [HttpPost]
public void TransfersReport(DateTime dateFrom, DateTime dateTo) public void TransfersReport(DateTime dateFrom, DateTime dateTo)
{ {
if (APIClient.Operator == null)
{
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');window.location.replace('/Home/Enter');</script>");
return;
}
MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo });
try try
{ {
_mailWorker.MailSendAsync(new MailSendInfoBindingModel _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{ {
Subject = "Отчёт о закупках", Subject = "Отчёт о закупках",
Text = "От банка \"Вы банкрот\"", Text = "Для оператора " + APIClient.Operator.LastName + APIClient.Operator.FirstName,
MailAddress = "", MailAddress = "",
FileName = "test.pdf", FileName = "test.pdf",
Attachment = report Attachment = report
}); });
Response.Redirect("/"); Response.WriteAsync($"<script language=\"javascript\">alert('Mail sent!');window.location.replace('/');</script>");
Redirect("/");
} }
catch (Exception ex) catch (Exception ex)
{ {