list and db fixes

This commit is contained in:
dasha 2023-04-11 00:07:47 +04:00
parent 5cc65fd547
commit f6be017910
5 changed files with 38 additions and 10 deletions

View File

@ -38,7 +38,7 @@ namespace SushiBarDatabaseImplement.Implements
.FirstOrDefault(x => x.Id == model.Id) .FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel; ?.GetViewModel;
} }
if (model.ImplementerId.HasValue && model.OrderStatus.HasValue) else if (model.ImplementerId.HasValue && model.OrderStatus.HasValue)
{ {
return context.Orders return context.Orders
.Include(x => x.Sushi) .Include(x => x.Sushi)
@ -46,6 +46,14 @@ namespace SushiBarDatabaseImplement.Implements
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus) .FirstOrDefault(x => x.ImplementerId == model.ImplementerId && x.Status == model.OrderStatus)
?.GetViewModel; ?.GetViewModel;
} }
else if (model.ImplementerId.HasValue)
{
return context.Orders
.Include(x => x.Sushi)
.Include(x => x.Client).Include(x => x.Implementer)
.FirstOrDefault(x => x.ImplementerId == model.ImplementerId)
?.GetViewModel;
}
return null; return null;
} }
@ -91,6 +99,7 @@ namespace SushiBarDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Sushi) .Include(x => x.Sushi)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.Select(x => x.GetViewModel) .Select(x => x.GetViewModel)
.ToList(); .ToList();
} }
@ -108,6 +117,7 @@ namespace SushiBarDatabaseImplement.Implements
return context.Orders return context.Orders
.Include(x => x.Sushi) .Include(x => x.Sushi)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == newOrder.Id) .FirstOrDefault(x => x.Id == newOrder.Id)
?.GetViewModel; ?.GetViewModel;
} }
@ -118,6 +128,7 @@ namespace SushiBarDatabaseImplement.Implements
var order = context.Orders var order = context.Orders
.Include(x => x.Sushi) .Include(x => x.Sushi)
.Include(x => x.Client) .Include(x => x.Client)
.Include(x => x.Implementer)
.FirstOrDefault(x => x.Id == model.Id); .FirstOrDefault(x => x.Id == model.Id);
if (order == null) if (order == null)
{ {

View File

@ -26,7 +26,7 @@ namespace SushiBarListImplement.Implements
{ {
var result = new List<OrderViewModel>(); var result = new List<OrderViewModel>();
if (model.DateFrom.HasValue) if (model.DateFrom.HasValue && model.DateTo.HasValue)
{ {
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
{ {
@ -46,6 +46,16 @@ namespace SushiBarListImplement.Implements
} }
} }
} }
else if (model.OrderStatus.HasValue)
{
foreach (var order in _source.Orders)
{
if (order.Status == model.OrderStatus)
{
result.Add(GetViewModel(order));
}
}
}
else if (model.Id.HasValue) else if (model.Id.HasValue)
{ {
foreach (var order in _source.Orders) foreach (var order in _source.Orders)
@ -92,6 +102,14 @@ namespace SushiBarListImplement.Implements
break; break;
} }
} }
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == order.ImplementerId)
{
viewModel.ImplementerFIO = implementer.ImplementerFIO;
break;
}
}
return viewModel; return viewModel;
} }
public OrderViewModel? Insert(OrderBindingModel model) public OrderViewModel? Insert(OrderBindingModel model)

View File

@ -1,11 +1,6 @@
using SushiBarContracts.BindingModels; using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SushiBarListImplement.Models namespace SushiBarListImplement.Models
{ {

View File

@ -2,7 +2,6 @@
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
using SushiBarDataModels.Enums; using SushiBarDataModels.Enums;
using SushiBarDataModels.Models; using SushiBarDataModels.Models;
using System.Reflection;
namespace SushiBarListImplement.Models namespace SushiBarListImplement.Models
{ {
@ -11,6 +10,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 ClientId { get; private set; }
public int? ImplementerId { 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.Неизвестен;
@ -26,6 +26,7 @@ namespace SushiBarListImplement.Models
{ {
SushiId = model.SushiId, SushiId = model.SushiId,
ClientId = model.ClientId, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -41,12 +42,14 @@ namespace SushiBarListImplement.Models
return; return;
} }
Status = model.Status; Status = model.Status;
ImplementerId = model.ImplementerId;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()
{ {
SushiId = SushiId, SushiId = SushiId,
ClientId = ClientId, ClientId = ClientId,
ImplementerId = ImplementerId,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
DateCreate = DateCreate, DateCreate = DateCreate,

View File

@ -3,6 +3,7 @@ using SushiBarContracts.BindingModels;
using SushiBarContracts.BusinessLogicsContracts; using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.SearchModels; using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels; using SushiBarContracts.ViewModels;
using SushiBarDataModels.Enums;
namespace SushiBarRestApi.Controllers namespace SushiBarRestApi.Controllers
{ {
@ -48,7 +49,7 @@ namespace SushiBarRestApi.Controllers
{ {
return _order.ReadList(new OrderSearchModel return _order.ReadList(new OrderSearchModel
{ {
//Status = OrderStatus.Принят OrderStatus = OrderStatus.Принят
}); });
} }
catch (Exception ex) catch (Exception ex)
@ -65,7 +66,7 @@ namespace SushiBarRestApi.Controllers
{ {
return _order.ReadElement(new OrderSearchModel return _order.ReadElement(new OrderSearchModel
{ {
//ImplementerId = implementerId ImplementerId = implementerId
}); });
} }
catch (Exception ex) catch (Exception ex)