update fix

This commit is contained in:
Alina Batylkina 2023-06-19 19:11:35 +03:00
parent 555afefd32
commit 36233b487a
11 changed files with 207 additions and 91 deletions

View File

@ -344,7 +344,7 @@ namespace CanteenManagerApp.Controllers
} }
[HttpPost] [HttpPost]
public void DishCreate(string name) public void DishCreate(string name, int price)
{ {
if (APIClient.Manager == null) if (APIClient.Manager == null)
{ {
@ -356,10 +356,16 @@ namespace CanteenManagerApp.Controllers
throw new Exception("Наименование блюда не должно быть пустым"); throw new Exception("Наименование блюда не должно быть пустым");
} }
if (price <= 0)
{
throw new Exception("Цена блюда должна быть больше нуля");
}
APIClient.PostRequest("api/main/dishcreate", new DishBindingModel APIClient.PostRequest("api/main/dishcreate", new DishBindingModel
{ {
ManagerId = APIClient.Manager.Id, ManagerId = APIClient.Manager.Id,
DishName = name DishName = name,
Price = price
}); });
Response.Redirect("DishList"); Response.Redirect("DishList");
@ -484,7 +490,7 @@ namespace CanteenManagerApp.Controllers
public void ReportPdf(ReportBindingModel model) public void ReportPdf(ReportBindingModel model)
{ {
model.UserId = APIClient.Manager.Id; model.UserId = APIClient.Manager.Id;
APIClient.PostRequest("api/main/SaveOrdersToPDF", model); APIClient.PostRequest("api/main/SaveCooksToPDF", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }
@ -492,7 +498,7 @@ namespace CanteenManagerApp.Controllers
public void ReportXsl(ReportBindingModel model) public void ReportXsl(ReportBindingModel model)
{ {
model.UserId = APIClient.Manager.Id; model.UserId = APIClient.Manager.Id;
APIClient.PostRequest("api/main/SavevToXSL", model); APIClient.PostRequest("api/main/SaveOrdersToXSL", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }

View File

@ -2,6 +2,9 @@
@{ @{
ViewData["Title"] = "CookUpdate"; ViewData["Title"] = "CookUpdate";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные повара</h2> <h2 class="display-4">Данные повара</h2>
</div> </div>
@ -12,11 +15,11 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">ФИО:</div> <div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="FIO" value="" /></div> <div class="col-8"><input type="text" name="FIO" id="FIO" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Должность:</div> <div class="col-4">Должность:</div>
<div class="col-8"><input type="text" name="position" value="" /></div> <div class="col-8"><input type="text" name="position" id="position" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
@ -24,21 +27,22 @@
</div> </div>
</form> </form>
<script> <script>
const cooks = []; $(document).ready(function () {
$('#Id').change(function () {
function populateFields() { var selectedCookId = $(this).val();
ViewBag.CookList.forEach(value => { var cooks = @Html.Raw(JsonConvert.SerializeObject(ViewBag.CookList));
cooks.push(value); var selectedCook;
for (var i = 0; i < cooks.length; i++) {
if (cooks[i].Id == selectedCookId) {
selectedCook = cooks[i];
break;
}
}
if (selectedCook) {
$('#FIO').val(selectedCook.FIO);
$('#position').val(selectedCook.Position);
}
}); });
var selectedCookId = document.getElementById("Id").value; $('#Id').val($('#Id option:first').val()).change();
var selectedCook = cooks.find(function (cook) { });
return cook.Id === selectedCookId;
});
//console.log(selectedCook.FIO);
if (selectedCook) {
document.getElementsByName("FIO")[0].value = selectedCook.FIO;
document.getElementsByName("position")[0].value = selectedCook.Position;
}
console.log(document.getElementsByName("FIO")[0].value);
}
</script> </script>

View File

@ -17,6 +17,12 @@
<input type="text" name="name" id="name" /> <input type="text" name="name" id="name" />
</div> </div>
</div> </div>
<div class="row">
<div class="col-4">Цена блюда:</div>
<div class="col-8">
<input type="text" name="price" id="price" />
</div>
</div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"> <div class="col-4">

View File

@ -1,21 +1,25 @@
@{ @using Newtonsoft.Json;
@{
ViewData["Title"] = "DishUpdate"; ViewData["Title"] = "DishUpdate";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные блюда</h2> <h2 class="display-4">Данные блюда</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Блюдо:</div> <div class="col-4">Блюдо:</div>
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.DishList, "Id", "DishName"))"></select></div> <div class="col-8"><select id="Id" name="Id" class="form-control" asp-items="@(new SelectList(@ViewBag.DishList, "Id", "DishName"))"></select></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Название:</div> <div class="col-4">Название:</div>
<div class="col-8"><input type="text" name="name" value="" /></div> <div class="col-8"><input type="text" name="name" id="name" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Цена:</div> <div class="col-4">Цена:</div>
<div class="col-8"><input type="text" name="price" value="" /></div> <div class="col-8"><input type="text" name="price" id="price" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
@ -23,16 +27,22 @@
</div> </div>
</form> </form>
<script> <script>
function populateFields() { $(document).ready(function () {
var selectedDishId = document.getElementById("dish").value; $('#Id').change(function () {
var dishes = @Json.Serialize(ViewBag.CookList); var selectedDishId = $(this).val();
var selectedDish = dishes.find(function (dish) { var dishes = @Html.Raw(JsonConvert.SerializeObject(ViewBag.DishList));
return dish.Id === selectedDishId; var selectedDish;
for (var i = 0; i < dishes.length; i++) {
if (dishes[i].Id == selectedDishId) {
selectedDish = dishes[i];
break;
}
}
if (selectedDish) {
$('#name').val(selectedDish.DishName);
$('#price').val(selectedDish.Price);
}
}); });
$('#Id').val($('#Id option:first').val()).change();
if (selectedDish) { });
document.getElementsByName("name")[0].value = selectedDish.DishName;
document.getElementsByName("price")[0].value = selectedDish.Price;
}
}
</script> </script>

View File

@ -1,6 +1,10 @@
@{ @using Newtonsoft.Json;
@{
ViewData["Title"] = "ProductUpdate"; ViewData["Title"] = "ProductUpdate";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные продукта</h2> <h2 class="display-4">Данные продукта</h2>
</div> </div>
@ -11,11 +15,11 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">ФИО:</div> <div class="col-4">ФИО:</div>
<div class="col-8"><input type="text" name="name" value="" /></div> <div class="col-8"><input type="text" name="name" id="name" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Цена:</div> <div class="col-4">Цена:</div>
<div class="col-8"><input type="text" name="price" value="" /></div> <div class="col-8"><input type="text" name="price" id="price" value="" /></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-8"></div> <div class="col-8"></div>
@ -23,16 +27,22 @@
</div> </div>
</form> </form>
<script> <script>
function populateFields() { $(document).ready(function () {
var selectedCookId = document.getElementById("product").value; $('#Id').change(function () {
var cooks = @Json.Serialize(ViewBag.CookList); var selectedProductId = $(this).val();
var selectedCook = cooks.find(function (cook) { var products = @Html.Raw(JsonConvert.SerializeObject(ViewBag.ProductList));
return cook.Id === selectedCookId; var selectedProduct;
for (var i = 0; i < products.length; i++) {
if (products[i].Id == selectedProductId) {
selectedProduct = products[i];
break;
}
}
if (selectedProduct) {
$('#name').val(selectedProduct.ProductName);
$('#price').val(selectedProduct.Price);
}
}); });
$('#Id').val($('#Id option:first').val()).change();
if (selectedCook) { });
document.getElementsByName("name")[0].value = selectedCook.ProductName;
document.getElementsByName("price")[0].value = selectedCook.Price;
}
}
</script> </script>

View File

@ -55,7 +55,7 @@ namespace CanteenRestApi.Controllers
} }
} }
[HttpPost] [HttpPost]
public void SaveOrdersToPDF(ReportBindingModel model) public void SaveCooksToPDF(ReportBindingModel model)
{ {
try try
{ {
@ -619,6 +619,19 @@ namespace CanteenRestApi.Controllers
} }
} }
[HttpGet] [HttpGet]
public LunchViewModel GetLunch(int lunchId)
{
try
{
return _lunch.ReadElement(new LunchSearchModel { Id = lunchId });
}
catch (Exception ex)
{
_logger.LogError(ex, "Error during loading list of bouquets");
throw;
}
}
[HttpGet]
public GraphicViewModel[] GetGraphic() public GraphicViewModel[] GetGraphic()
{ {
return new GraphicViewModel[] return new GraphicViewModel[]

View File

@ -530,6 +530,7 @@ namespace CanteenVisitorApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Report() public IActionResult Report()
{ {
ViewBag.LunchList = APIClient.GetRequest<List<LunchViewModel>>($"api/main/getlunchlist?visitorId={APIClient.Visitor.Id}");
return View(new ReportBindingModel()); return View(new ReportBindingModel());
} }
[HttpPost] [HttpPost]
@ -559,6 +560,13 @@ namespace CanteenVisitorApp.Controllers
[HttpPost] [HttpPost]
public void ReportEmail(ReportBindingModel model) public void ReportEmail(ReportBindingModel model)
{ {
model.UserId = APIClient.Visitor.Id;
APIClient.PostRequest($"api/visitor/SendEmail", new MailSendInfoBindingModel
{
MailAddress = APIClient.Visitor.Login,
Subject = "Отчет",
report = model
});
APIClient.PostRequest("api/main/SaveCooksToEMAIL", model); APIClient.PostRequest("api/main/SaveCooksToEMAIL", model);
Response.Redirect("Index"); Response.Redirect("Index");
} }

View File

@ -5,27 +5,38 @@
ViewBag.Title = "Report"; ViewBag.Title = "Report";
} }
<h2>Generate Report</h2> <h2>Отчеты</h2>
@using (Html.BeginForm("Report", "Home", FormMethod.Post)) @using (Html.BeginForm("Report", "Home", FormMethod.Post))
{ {
<div> <div class="row">
@Html.LabelFor(m => m.FileName) <h4>Pdf</h4>
@Html.TextBoxFor(m => m.FileName) <div class="col-md-6">
<div class="form-group">
@Html.LabelFor(m => m.DateBefore, "От")
@Html.TextBoxFor(m => m.DateBefore, new { type = "date", @class = "form-control" })
</div>
</div>
<div class="col-md-6">
<div class="form-group">
@Html.LabelFor(m => m.DateAfter, "До")
@Html.TextBoxFor(m => m.DateAfter, new { type = "date", @class = "form-control" })
</div>
</div>
</div>
<div class="form-group mt-2">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportPdf", "Home")">Сохранить в pdf</button>
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportEmail", "Home")">Отправить pdf по почте</button>
</div> </div>
<div> <div class="mt-3">
@Html.LabelFor(m => m.DateAfter) <h4>Word, Excel</h4>
@Html.TextBoxFor(m => m.DateAfter, new { type = "date" }) <div class="form-group mb-2">
@Html.LabelFor(m => m.LunchId, "Выбранные обеды")
@Html.DropDownListFor(m => m.LunchId, new SelectList(ViewBag.LunchList, "Id", "LunchName"), new { @class = "form-control", multiple = "multiple" })
</div>
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportXsl", "Home")">Сохранить в excel</button>
<button type="submit" class="btn btn-primary" formaction="@Url.Action("ReportWord", "Home")">Сохранить в word</button>
</div> </div>
<div>
@Html.LabelFor(m => m.DateBefore)
@Html.TextBoxFor(m => m.DateBefore, new { type = "date" })
</div>
<button type="submit" formaction="@Url.Action("ReportPdf", "Home")">Сохранить в pfd</button>
<button type="submit" formaction="@Url.Action("ReportEmail", "Home")">Отправить по почте</button>
<button type="submit" formaction="@Url.Action("ReportXsl", "Home")">Сохранить в excel</button>
<button type="submit" formaction="@Url.Action("ReportWord", "Home")">Сохранить в word</button>
} }

View File

@ -2,6 +2,9 @@
@{ @{
ViewData["Title"] = "UpdateLunch"; ViewData["Title"] = "UpdateLunch";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные обеда</h2> <h2 class="display-4">Данные обеда</h2>
</div> </div>
@ -20,4 +23,23 @@
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div> </div>
</form> </form>
<script>
$(document).ready(function () {
$('#Id').change(function () {
var selectedLunchId = $(this).val();
var lunches = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Lunches));
var selectedLunch;
for (var i = 0; i < lunches.length; i++) {
if (lunches[i].Id == selectedLunchId) {
selectedLunch = lunches[i];
break;
}
}
if (selectedLunch) {
$('#name').val(selectedLunch.LunchName);
}
});
$('#Id').val($('#Id option:first').val()).change();
});
</script>

View File

@ -2,13 +2,16 @@
@{ @{
ViewData["Title"] = "UpdateOrder"; ViewData["Title"] = "UpdateOrder";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные заказа</h2> <h2 class="display-4">Данные заказа</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Заказ:</div> <div class="col-4">Заказ:</div>
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Orders, "Id", "Id"))"></select></div> <div class="col-8"><select id="Id" name="Id" class="form-control" asp-items="@(new SelectList(@ViewBag.Orders, "Id", "Id"))"></select></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Пожелания:</div> <div class="col-4">Пожелания:</div>
@ -20,4 +23,23 @@
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div> </div>
</form> </form>
<script>
$(document).ready(function () {
$('#Id').change(function () {
var selectedOrderId = $(this).val();
var orders = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Orders));
var selectedOrder;
for (var i = 0; i < orders.length; i++) {
if (orders[i].Id == selectedOrderId) {
selectedOrder = orders[i];
break;
}
}
if (selectedOrder) {
$('#description').val(selectedOrder.Description);
}
});
$('#Id').val($('#Id option:first').val()).change();
});
</script>

View File

@ -2,13 +2,16 @@
@{ @{
ViewData["Title"] = "UpdateTableware"; ViewData["Title"] = "UpdateTableware";
} }
<header>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</header>
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Данные прибора</h2> <h2 class="display-4">Данные прибора</h2>
</div> </div>
<form method="post"> <form method="post">
<div class="row"> <div class="row">
<div class="col-4">Прибор:</div> <div class="col-4">Прибор:</div>
<div class="col-8"><select id="Id" name="Id" class="form-control" onchange="populateFields()" asp-items="@(new SelectList(@ViewBag.Tablewares, "Id", "TablewareName"))"></select></div> <div class="col-8"><select id="Id" name="Id" class="form-control" asp-items="@(new SelectList(@ViewBag.Tablewares, "Id", "TablewareName"))"></select></div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Название прибора:</div> <div class="col-4">Название прибора:</div>
@ -20,23 +23,24 @@
<div class="col-8"></div> <div class="col-8"></div>
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div> <div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
</div> </div>
</form>@* </form>
<script> <script>
const tablewars = []; $(document).ready(function () {
$('#Id').change(function () {
function populateFields() { var selectedTablewareId = $(this).val();
ViewBag.Tablewares.forEach(value => { var tablewares = @Html.Raw(JsonConvert.SerializeObject(ViewBag.Tablewares));
tablewars.push(value); var selectedTableware;
for (var i = 0; i < tablewares.length; i++) {
if (tablewares[i].Id == selectedTablewareId) {
selectedTableware = tablewares[i];
break;
}
}
console.log(selectedTableware);
if (selectedTableware) {
$('#TablewareName').val(selectedTableware.TablewareName);
}
}); });
var selectedTablewareId = document.getElementById("Id").value; $('#Id').val($('#Id option:first').val()).change();
var selectedTableware = tablewares.find(function (tableware) { });
return tableware.Id === selectedTablewareId; </script>
});
//console.log(selectedCook.FIO);
if (selectedTableware) {
document.getElementsByName("TablewareName")[0].value = selectedTableware.TablewareName;
document.getElementsByName("TablewareCount")[0].value = selectedTableware.TablewareCount;
}
console.log(document.getElementsByName("TablewareName")[0].value);
}
</script>*@