правки

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

@ -8,28 +8,23 @@
<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>
<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" id="sum" name="sum" readonly /></div>
<input type="text" id="sum" name="sum" readonly />
</div>
</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"><input type="submit" value="Создать" class="btn btn-primary" /></div>
<input type="submit" value="Создать" class="btnbtn-primary" />
</div>
</div> </div>
</form> </form>
<script> <script>
$('#sushi').on('change', function () { $('#sushi').on('change', function () {
check(); check();
@ -37,13 +32,15 @@
$('#count').on('change', function () { $('#count').on('change', function () {
check(); check();
}); });
function check() { function check() {
var count = $('#count').val(); var count = $('#count').val();
var sushi = $('#sushi').val(); var sushi = $('#sushi').val();
if (count && sushi) { if (count && sushi) {
$.ajax({ $.ajax({
method: "POST", method: "POST",
url: "/Home/Calc", data: { count: count, sushi: sushi }, url: "/Home/Calc",
data: { count: count, sushi: sushi },
success: function (result) { success: function (result) {
$("#sum").val(result); $("#sum").val(result);
} }

View File

@ -1,11 +1,16 @@
@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)
@ -13,6 +18,7 @@
<h3 class="display-4">Авторизируйтесь</h3> <h3 class="display-4">Авторизируйтесь</h3>
return; return;
} }
<p> <p>
<a asp-action="Create">Создать заказ</a> <a asp-action="Create">Создать заказ</a>
</p> </p>
@ -23,7 +29,7 @@
Номер Номер
</th> </th>
<th> <th>
Изделие Суши
</th> </th>
<th> <th>
Дата создания Дата создания
@ -44,28 +50,22 @@
{ {
<tr> <tr>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.Id)
item.Id)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.SushiName)
item.SushiName)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.DateCreate)
item.DateCreate)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.Count)
item.Count)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.Sum)
item.Sum)
</td> </td>
<td> <td>
@Html.DisplayFor(modelItem => @Html.DisplayFor(modelItem => item.Status)
item.Status)
</td> </td>
</tr> </tr>
} }

View File

@ -13,6 +13,9 @@ namespace SushiBarContracts.ViewModels
{ {
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int ClientId { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
public int SushiId { get; set; } public int SushiId { get; set; }
[DisplayName("Изделие")] [DisplayName("Изделие")]
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;

View File

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

View File

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

View File

@ -14,6 +14,7 @@ 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 ClientId { get; private set; }
public int SushiId { 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; }
@ -31,6 +32,7 @@ namespace SushiBarFileImplement.Models
{ {
Id = model.Id, Id = model.Id,
SushiId = model.SushiId, SushiId = model.SushiId,
ClientId = model.ClientId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -50,6 +52,7 @@ 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),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.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)),
@ -73,6 +76,7 @@ namespace SushiBarFileImplement.Models
{ {
Id = Id, Id = Id,
SushiId = SushiId, SushiId = SushiId,
ClientId = ClientId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
@ -83,6 +87,7 @@ 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("ClientId", ClientId.ToString()),
new XElement("Count", Count.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()),

View File

@ -24,11 +24,22 @@ namespace SushiBarFileImplement.Implements
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();
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) public OrderViewModel? GetElement(OrderSearchModel model)
@ -39,7 +50,23 @@ 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;
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) 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;

View File

@ -14,6 +14,7 @@ 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 ClientId { 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.Неизвестен;
@ -30,6 +31,7 @@ namespace SushiBarListImplement.Models
{ {
Id = model.Id, Id = model.Id,
SushiId = model.SushiId, SushiId = model.SushiId,
ClientId = model.ClientId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -52,6 +54,7 @@ namespace SushiBarListImplement.Models
{ {
Id = Id, Id = Id,
SushiId = SushiId, SushiId = SushiId,
ClientId = ClientId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,

View File

@ -33,20 +33,61 @@ namespace SushiBarListImplement.Implements
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)
{
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) foreach (var order in _source.Orders)
{ {
if (order.Id == model.Id) if (order.Id == model.Id)
{ {
result.Add(AttachSushiName(order.GetViewModel)); result.Add(GetViewModel(order));
}
} }
} }
return result; return result;
} }
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) public OrderViewModel? GetElement(OrderSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)