правки

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]
public IActionResult Create()
{
ViewBag.Sushis =
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
return View();
}
[HttpPost]

View File

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

View File

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

View File

@ -13,6 +13,9 @@ namespace SushiBarContracts.ViewModels
{
[DisplayName("Номер")]
public int Id { 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;

View File

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

View File

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

View File

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

View File

@ -24,11 +24,22 @@ namespace SushiBarFileImplement.Implements
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)
@ -39,7 +50,23 @@ namespace SushiBarFileImplement.Implements
}
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)
{
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 SushiId { 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.Неизвестен;
@ -30,6 +31,7 @@ namespace SushiBarListImplement.Models
{
Id = model.Id,
SushiId = model.SushiId,
ClientId = model.ClientId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -52,6 +54,7 @@ namespace SushiBarListImplement.Models
{
Id = Id,
SushiId = SushiId,
ClientId = ClientId,
Count = Count,
Sum = Sum,
Status = Status,

View File

@ -33,20 +33,61 @@ namespace SushiBarListImplement.Implements
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
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)
{
if (order.Id == model.Id)
{
result.Add(AttachSushiName(order.GetViewModel));
result.Add(GetViewModel(order));
}
}
}
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)
{
if (!model.Id.HasValue)