правки

This commit is contained in:
Андрей Байгулов 2024-05-03 22:00:08 +04:00
parent c920c54e17
commit 429a35d868
10 changed files with 238 additions and 154 deletions

View File

@ -112,8 +112,7 @@ namespace SushiBarClientApp.Controllers
[HttpGet] [HttpGet]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.Sushis = ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
return View(); return View();
} }
[HttpPost] [HttpPost]

View File

@ -1,53 +1,50 @@
@{ @{
ViewData["Title"] = "Create"; ViewData["Title"] = "Create";
} }
<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"> <div class="col-8">
<select id="sushi" name="sushi" class="form-control" aspitems="@(new SelectList(@ViewBag.sushis,"Id", "SushiName"))"></select> <select id="sushi" name="sushi" class="form-control" asp-items="@(new SelectList(@ViewBag.Sushis,"Id", "SushiName"))"></select>
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<div class="col-4">Количество:</div> <div class="col-4">Количество:</div>
<div class="col-8"> <div class="col-8"><input type="text" name="count" id="count" /></div>
<input type="text" name="count" id="count" /> </div>
</div> <div class="row">
</div> <div class="col-4">Сумма:</div>
<div class="row"> <div class="col-8"><input type="text" id="sum" name="sum" readonly /></div>
<div class="col-4">Сумма:</div> </div>
<div class="col-8"> <div class="row">
<input type="text" id="sum" name="sum" readonly /> <div class="col-8"></div>
</div> <div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
</div> </div>
<div class="row">
<div class="col-8"></div>
<div class="col-4">
<input type="submit" value="Создать" class="btnbtn-primary" />
</div>
</div>
</form> </form>
<script> <script>
$('#sushi').on('change', function () { $('#sushi').on('change', function () {
check(); check();
}); });
$('#count').on('change', function () { $('#count').on('change', function () {
check(); check();
}); });
function check() {
var count = $('#count').val(); function check() {
var sushi = $('#sushi').val(); var count = $('#count').val();
if (count && sushi) { var sushi = $('#sushi').val();
$.ajax({ if (count && sushi) {
method: "POST", $.ajax({
url: "/Home/Calc", data: { count: count, sushi: sushi }, method: "POST",
success: function (result) { url: "/Home/Calc",
$("#sum").val(result); data: { count: count, sushi: sushi },
} success: function (result) {
}); $("#sum").val(result);
}; }
} });
};
}
</script> </script>

View File

@ -1,75 +1,75 @@
@using SushiBarContracts.ViewModels @using SushiBarContracts.ViewModels
@model List<OrderViewModel> @model List<OrderViewModel>
@{ @{
ViewData["Title"] = "Home Page"; ViewData["Title"] = "Home Page";
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Заказы</h1> <h1 class="display-4">Заказы</h1>
</div> </div>
<div class="text-center"> <div class="text-center">
@{ @{
if (Model == null) if (Model == null)
{ {
<h3 class="display-4">Авторизируйтесь</h3> <h3 class="display-4">Авторизируйтесь</h3>
return; return;
} }
<p>
<a asp-action="Create">Создать заказ</a> <p>
</p> <a asp-action="Create">Создать заказ</a>
<table class="table"> </p>
<thead> <table class="table">
<tr> <thead>
<th> <tr>
Номер <th>
</th> Номер
<th> </th>
Изделие <th>
</th> Суши
<th> </th>
Дата создания <th>
</th> Дата создания
<th> </th>
Количество <th>
</th> Количество
<th> </th>
Сумма <th>
</th> Сумма
<th> </th>
Статус <th>
</th> Статус
</tr> </th>
</thead> </tr>
<tbody> </thead>
@foreach (var item in Model) <tbody>
{ @foreach (var item in Model)
<tr> {
<td> <tr>
@Html.DisplayFor(modelItem => <td>
item.Id) @Html.DisplayFor(modelItem => item.Id)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.SushiName)
item.SushiName) </td>
</td> <td>
<td> @Html.DisplayFor(modelItem => item.DateCreate)
@Html.DisplayFor(modelItem => </td>
item.DateCreate) <td>
</td> @Html.DisplayFor(modelItem => item.Count)
<td> </td>
@Html.DisplayFor(modelItem => <td>
item.Count) @Html.DisplayFor(modelItem => item.Sum)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.Status)
item.Sum) </td>
</td> </tr>
<td> }
@Html.DisplayFor(modelItem => </tbody>
item.Status) </table>
</td> }
</tr>
}
</tbody>
</table>
}
</div> </div>

View File

@ -13,7 +13,10 @@ namespace SushiBarContracts.ViewModels
{ {
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } 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("Изделие")] [DisplayName("Изделие")]
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]

View File

@ -10,7 +10,8 @@ namespace SushiBarDataModels.Models
public interface IOrderModel : IId public interface IOrderModel : IId
{ {
int SushiId { get; } int SushiId { get; }
int Count { get; } int ClientId { get; }
int Count { get; }
double Sum { get; } double Sum { get; }
OrderStatus Status { get; } OrderStatus Status { get; }
DateTime DateCreate { get; } DateTime DateCreate { get; }

View File

@ -9,8 +9,12 @@ namespace SushiBarDatabaseImplement.Models
public class Order : IOrderModel public class Order : IOrderModel
{ {
public int Id { get; private set; } 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 int SushiId { get; private set; }
public virtual Sushi Sushi { get; set; } = new(); public virtual Sushi Sushi { get; set; } = new();
@ -34,7 +38,9 @@ namespace SushiBarDatabaseImplement.Models
return new Order() return new Order()
{ {
Id = model.Id, 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), Sushi = context.Sushis.First(x => x.Id == model.SushiId),
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
@ -57,7 +63,9 @@ namespace SushiBarDatabaseImplement.Models
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
Id = Id, Id = Id,
SushiId = SushiId, ClientId = ClientId,
ClientFIO = Client.ClientFIO,
SushiId = SushiId,
SushiName = Sushi.SushiName, SushiName = Sushi.SushiName,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,

View File

@ -14,7 +14,8 @@ namespace SushiBarFileImplement.Models
internal class Order : IOrderModel internal class Order : IOrderModel
{ {
public int Id { get; private set; } 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 int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
@ -31,7 +32,8 @@ namespace SushiBarFileImplement.Models
{ {
Id = model.Id, Id = model.Id,
SushiId = model.SushiId, SushiId = model.SushiId,
Count = model.Count, ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
@ -50,7 +52,8 @@ namespace SushiBarFileImplement.Models
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
SushiId = Convert.ToInt32(element.Element("SushiId")!.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), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)), Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value), DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
@ -73,7 +76,8 @@ namespace SushiBarFileImplement.Models
{ {
Id = Id, Id = Id,
SushiId = SushiId, SushiId = SushiId,
Count = Count, ClientId = ClientId,
Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,
@ -83,7 +87,8 @@ namespace SushiBarFileImplement.Models
public XElement GetXElement => new("Order", public XElement GetXElement => new("Order",
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("SushiId", SushiId.ToString()), 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("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()), new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()), new XElement("DateCreate", DateCreate.ToString()),

View File

@ -22,16 +22,27 @@ namespace SushiBarFileImplement.Implements
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList(); public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachSushiName(x.GetViewModel)).ToList();
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (model.DateFrom.HasValue)
{ {
return new(); return source.Orders.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
} .Select(x => GetViewModel(x)).ToList();
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachSushiName(x.GetViewModel)).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) if (!model.Id.HasValue)
{ {
@ -39,8 +50,24 @@ namespace SushiBarFileImplement.Implements
} }
return AttachSushiName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel); 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; model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model); var newOrder = Order.Create(model);

View File

@ -14,7 +14,8 @@ namespace SushiBarListImplement.Models
{ {
public int Id { get; private set; } public int Id { get; private set; }
public int SushiId { 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 double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now; public DateTime DateCreate { get; private set; } = DateTime.Now;
@ -30,7 +31,8 @@ namespace SushiBarListImplement.Models
{ {
Id = model.Id, Id = model.Id,
SushiId = model.SushiId, SushiId = model.SushiId,
Count = model.Count, ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
DateCreate = model.DateCreate, DateCreate = model.DateCreate,
@ -52,7 +54,8 @@ namespace SushiBarListImplement.Models
{ {
Id = Id, Id = Id,
SushiId = SushiId, SushiId = SushiId,
Count = Count, ClientId = ClientId,
Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
DateCreate = DateCreate, DateCreate = DateCreate,

View File

@ -30,24 +30,65 @@ namespace SushiBarListImplement.Implements
return result; return result;
} }
public List<OrderViewModel> GetFilteredList(OrderSearchModel model) public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{ {
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
if (model == null || !model.Id.HasValue) if (model.DateFrom.HasValue)
{ {
return result; foreach (var order in _source.Orders)
} {
foreach (var order in _source.Orders) if (order.DateCreate >= model.DateFrom && order.DateCreate <= model.DateTo)
{ {
if (order.Id == model.Id) result.Add(GetViewModel(order));
{ }
result.Add(AttachSushiName(order.GetViewModel)); }
} }
} else if (model.ClientId.HasValue && !model.Id.HasValue)
return result; {
} 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) if (!model.Id.HasValue)
{ {