ISEbd-21 Melnikov I.O. Lab Work 05 Base #11
@ -44,7 +44,7 @@
|
||||
</div>
|
||||
<footer class="border-top footer text-muted">
|
||||
<div class="container">
|
||||
© 2020 - Абстрактный магазин - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
|
||||
© 2023 - Кузнечная мастерская - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</div>
|
||||
</footer>
|
||||
<script src="~/js/site.js" asp-append-version="true"></script>
|
||||
|
@ -22,6 +22,6 @@ namespace BlacksmithWorkshopContracts.ViewModels
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public int ClientId { get; set; }
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -51,6 +51,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
var existingClient = context.Clients.FirstOrDefault(x => x.Email == newClient.Email);//проверка на уникальность
|
||||
if (existingClient != null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Clients.Add(newClient);
|
||||
context.SaveChanges();
|
||||
return newClient.GetViewModel;
|
||||
|
@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels;
|
||||
using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
@ -12,7 +13,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDatabase();
|
||||
List<OrderViewModel> orderList = context.Orders
|
||||
.Select(x => x.GetViewModel)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
foreach (var order in orderList)
|
||||
{
|
||||
@ -34,6 +36,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
orderList = context.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -41,14 +44,16 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
orderList = context.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
else if (model.ClientId.HasValue)
|
||||
{
|
||||
orderList = context.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
foreach (var order in orderList)
|
||||
|
@ -22,6 +22,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
public Client? Client { get; private set; }//вспомогательное поле для получения ФИО клиента
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -51,7 +52,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
@ -75,7 +75,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
ClientFIO = Client?.ClientFIO ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
private OrderViewModel AddManufactureName (OrderViewModel model)
|
||||
private OrderViewModel AddManufactureAndClientName (OrderViewModel model)
|
||||
{
|
||||
model.ManufactureName = source.Manufactures.SingleOrDefault(x => x.Id == model.ManufactureId)?.ManufactureName ?? string.Empty;
|
||||
return model;
|
||||
@ -22,7 +22,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders
|
||||
.Select(x => AddManufactureName(x.GetViewModel))
|
||||
.Select(x => AddManufactureAndClientName(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
@ -35,21 +35,21 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => AddManufactureName(x.GetViewModel))
|
||||
.Select(x => AddManufactureAndClientName(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
else if (model.DateFrom.HasValue && model.DateTo.HasValue)//если Id в модели нет, ищем по датам
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => AddManufactureName(x.GetViewModel))
|
||||
.Select(x => AddManufactureAndClientName(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
else if (model.ClientId.HasValue)//далее ищем по Id клиента
|
||||
{
|
||||
return source.Orders
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => AddManufactureName(x.GetViewModel))
|
||||
.Select(x => AddManufactureAndClientName(x.GetViewModel))
|
||||
.ToList();
|
||||
}
|
||||
return new();//если нет ни того, ни другого, ни третьего, возвращаем пустой список
|
||||
@ -65,7 +65,7 @@ namespace BlacksmithWorkshopFileImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return AddManufactureName(order);
|
||||
return AddManufactureAndClientName(order);
|
||||
}
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
|
@ -78,7 +78,6 @@ namespace BlacksmithWorkshopFileImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
};
|
||||
public XElement GetXElement => new
|
||||
(
|
||||
|
@ -69,6 +69,10 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
model.Id = client.Id + 1;
|
||||
}
|
||||
if (client.Email == model.Email)//проверка на уникальность
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
var res = Client.Create(model);
|
||||
if (res != null)
|
||||
|
@ -21,6 +21,8 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
OrderViewModel vm = order.GetViewModel;
|
||||
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
|
||||
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
|
||||
var client = _source.Clients.Find(x => x.Id == order.ClientId);
|
||||
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
|
||||
result.Add(vm);
|
||||
}
|
||||
return result;
|
||||
@ -41,7 +43,9 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
OrderViewModel vm = order.GetViewModel;
|
||||
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
|
||||
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
|
||||
result.Add(vm);
|
||||
var client = _source.Clients.Find(x => x.Id == order.ClientId);
|
||||
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
|
||||
result.Add(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -54,7 +58,9 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
OrderViewModel vm = order.GetViewModel;
|
||||
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
|
||||
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
|
||||
result.Add(vm);
|
||||
var client = _source.Clients.Find(x => x.Id == order.ClientId);
|
||||
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
|
||||
result.Add(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,7 +73,9 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
OrderViewModel vm = order.GetViewModel;
|
||||
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
|
||||
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
|
||||
result.Add(vm);
|
||||
var client = _source.Clients.Find(x => x.Id == order.ClientId);
|
||||
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
|
||||
result.Add(vm);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -83,8 +91,13 @@ namespace BlacksmithWorkshopListImplement.Implements
|
||||
{
|
||||
if (model.Id.HasValue && order.Id == model.Id)
|
||||
{
|
||||
return order.GetViewModel;
|
||||
}
|
||||
OrderViewModel vm = order.GetViewModel;
|
||||
var manufacture = _source.Manufactures.Find(x => x.Id == order.ManufactureId);
|
||||
vm.ManufactureName = manufacture?.ManufactureName ?? string.Empty;
|
||||
var client = _source.Clients.Find(x => x.Id == order.ClientId);
|
||||
vm.ClientFIO = client?.ClientFIO ?? string.Empty;
|
||||
return vm;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -55,7 +55,6 @@ namespace BlacksmithWorkshopListImplement.Models
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user