ISEbd-21 Melnikov I.O. Lab Work 05 Base #11

Closed
Igor-Melnikov wants to merge 15 commits from lab5 into lab4
10 changed files with 45 additions and 20 deletions
Showing only changes of commit 99a55d7622 - Show all commits

View File

@ -44,7 +44,7 @@
</div>
<footer class="border-top footer text-muted">
<div class="container">
&copy; 2020 - Абстрактный магазин - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
&copy; 2023 - Кузнечная мастерская - <a asp-area="" aspcontroller="Home" asp-action="Privacy">Личные данные</a>
</div>
</footer>
<script src="~/js/site.js" asp-append-version="true"></script>

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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)

View File

@ -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
};
}
}

View File

@ -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)
{

View File

@ -78,7 +78,6 @@ namespace BlacksmithWorkshopFileImplement.Models
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ClientId = ClientId
};
public XElement GetXElement => new
(

View File

@ -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)

View File

@ -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;
}

View File

@ -55,7 +55,6 @@ namespace BlacksmithWorkshopListImplement.Models
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
ClientId = ClientId
};
}
}