ISEbd-22. Baygulov A.A. Lab work 05 #8
@ -112,8 +112,7 @@ namespace SushiBarClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewBag.Sushis =
|
||||
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
||||
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
|
@ -1,53 +1,50 @@
|
||||
@{
|
||||
ViewData["Title"] = "Create";
|
||||
ViewData["Title"] = "Create";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h2 class="display-4">Создание заказа</h2>
|
||||
<h2 class="display-4">Создание заказа</h2>
|
||||
</div>
|
||||
<form method="post">
|
||||
<div class="row">
|
||||
<div class="col-4">Изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="sushi" name="sushi" class="form-control" aspitems="@(new SelectList(@ViewBag.sushis,"Id", "SushiName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" name="count" id="count" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8">
|
||||
<input type="text" id="sum" name="sum" readonly />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Создать" class="btnbtn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Изделие:</div>
|
||||
<div class="col-8">
|
||||
<select id="sushi" name="sushi" class="form-control" asp-items="@(new SelectList(@ViewBag.Sushis,"Id", "SushiName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Количество:</div>
|
||||
<div class="col-8"><input type="text" name="count" id="count" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">Сумма:</div>
|
||||
<div class="col-8"><input type="text" id="sum" name="sum" readonly /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
$('#sushi').on('change', function () {
|
||||
check();
|
||||
});
|
||||
$('#count').on('change', function () {
|
||||
check();
|
||||
});
|
||||
function check() {
|
||||
var count = $('#count').val();
|
||||
var sushi = $('#sushi').val();
|
||||
if (count && sushi) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/Calc", data: { count: count, sushi: sushi },
|
||||
success: function (result) {
|
||||
$("#sum").val(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
$('#sushi').on('change', function () {
|
||||
check();
|
||||
});
|
||||
$('#count').on('change', function () {
|
||||
check();
|
||||
});
|
||||
|
||||
function check() {
|
||||
var count = $('#count').val();
|
||||
var sushi = $('#sushi').val();
|
||||
if (count && sushi) {
|
||||
$.ajax({
|
||||
method: "POST",
|
||||
url: "/Home/Calc",
|
||||
data: { count: count, sushi: sushi },
|
||||
success: function (result) {
|
||||
$("#sum").val(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
</script>
|
||||
|
@ -1,75 +1,75 @@
|
||||
@using SushiBarContracts.ViewModels
|
||||
|
||||
@model List<OrderViewModel>
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
ViewData["Title"] = "Home Page";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
<h1 class="display-4">Заказы</h1>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="text-center">
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
<p>
|
||||
<a asp-action="Create">Создать заказ</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Изделие
|
||||
</th>
|
||||
<th>
|
||||
Дата создания
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.SushiName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.DateCreate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Count)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Sum)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Status)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
@{
|
||||
if (Model == null)
|
||||
{
|
||||
<h3 class="display-4">Авторизируйтесь</h3>
|
||||
return;
|
||||
}
|
||||
|
||||
<p>
|
||||
<a asp-action="Create">Создать заказ</a>
|
||||
</p>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Номер
|
||||
</th>
|
||||
<th>
|
||||
Суши
|
||||
</th>
|
||||
<th>
|
||||
Дата создания
|
||||
</th>
|
||||
<th>
|
||||
Количество
|
||||
</th>
|
||||
<th>
|
||||
Сумма
|
||||
</th>
|
||||
<th>
|
||||
Статус
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Id)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.SushiName)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.DateCreate)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Count)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Sum)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Status)
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
}
|
||||
</div>
|
@ -13,7 +13,10 @@ namespace SushiBarContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int SushiId { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("ФИО клиента")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int SushiId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string SushiName { get; set; } = string.Empty;
|
||||
[DisplayName("Количество")]
|
||||
|
@ -10,7 +10,8 @@ namespace SushiBarDataModels.Models
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int SushiId { get; }
|
||||
int Count { get; }
|
||||
int ClientId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
|
@ -9,8 +9,12 @@ namespace SushiBarDatabaseImplement.Models
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
[Required]
|
||||
public virtual Client Client { get; private set; } = new();
|
||||
|
||||
[Required]
|
||||
public int SushiId { get; private set; }
|
||||
|
||||
public virtual Sushi Sushi { get; set; } = new();
|
||||
@ -34,7 +38,9 @@ namespace SushiBarDatabaseImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
ClientId = model.ClientId,
|
||||
Client = context.Clients.First(x => x.Id == model.ClientId),
|
||||
SushiId = model.SushiId,
|
||||
Sushi = context.Sushis.First(x => x.Id == model.SushiId),
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
@ -57,7 +63,9 @@ namespace SushiBarDatabaseImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
SushiId = SushiId,
|
||||
SushiName = Sushi.SushiName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
|
@ -14,7 +14,8 @@ namespace SushiBarFileImplement.Models
|
||||
internal class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int SushiId { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int SushiId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
@ -31,7 +32,8 @@ namespace SushiBarFileImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
Count = model.Count,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
@ -50,7 +52,8 @@ namespace SushiBarFileImplement.Models
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
SushiId = Convert.ToInt32(element.Element("SushiId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
@ -73,7 +76,8 @@ namespace SushiBarFileImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
Count = Count,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
@ -83,7 +87,8 @@ namespace SushiBarFileImplement.Models
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("SushiId", SushiId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("ClientId", ClientId.ToString()),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
new XElement("Status", Status.ToString()),
|
||||
new XElement("DateCreate", DateCreate.ToString()),
|
||||
|
@ -22,16 +22,27 @@ namespace SushiBarFileImplement.Implements
|
||||
|
||||
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList();
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachSushiName(x.GetViewModel)).ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (model.DateFrom.HasValue)
|
||||
{
|
||||
return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
if (model.ClientId.HasValue && !model.Id.HasValue)
|
||||
{
|
||||
return source.Orders.Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
if (model.Id.HasValue)
|
||||
{
|
||||
return source.Orders.Where(x => x.Id.Equals(model.Id)).Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
return new();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
@ -39,8 +50,24 @@ namespace SushiBarFileImplement.Implements
|
||||
}
|
||||
return AttachSushiName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||
}
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
var sushi = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
|
||||
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||
|
||||
if (sushi != null)
|
||||
{
|
||||
viewModel.SushiName = sushi.SushiName;
|
||||
}
|
||||
if (client != null)
|
||||
{
|
||||
viewModel.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
|
@ -14,7 +14,8 @@ namespace SushiBarListImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public int SushiId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public int ClientId { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
public double Sum { get; private set; }
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
@ -30,7 +31,8 @@ namespace SushiBarListImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
SushiId = model.SushiId,
|
||||
Count = model.Count,
|
||||
ClientId = model.ClientId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
@ -52,7 +54,8 @@ namespace SushiBarListImplement.Models
|
||||
{
|
||||
Id = Id,
|
||||
SushiId = SushiId,
|
||||
Count = Count,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
|
@ -30,24 +30,65 @@ namespace SushiBarListImplement.Implements
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model == null || !model.Id.HasValue)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(AttachSushiName(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
var result = new List<OrderViewModel>();
|
||||
if (model.DateFrom.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.ClientId.HasValue && !model.Id.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (model.Id.HasValue)
|
||||
{
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(GetViewModel(order));
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
foreach (var package in _source.Sushis)
|
||||
{
|
||||
if (package.Id == order.SushiId)
|
||||
{
|
||||
viewModel.SushiName = package.SushiName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Id == order.ClientId)
|
||||
{
|
||||
viewModel.ClientFIO = client.ClientFIO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user