lab3 corricting finished
This commit is contained in:
parent
be9e85574b
commit
ad9bc8e6bc
@ -17,8 +17,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Components
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
||||
model)
|
||||
@ -29,9 +29,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Components
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
@ -41,11 +41,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Components
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||
model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
||||
model.ComponentName) ||
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
|
@ -18,11 +18,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Manufactures
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model)
|
||||
{
|
||||
@ -32,11 +32,11 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Manufactures.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.ManufactureName.Contains(model.ManufactureName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.ManufactureName.Contains(model.ManufactureName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public ManufactureViewModel? GetElement(ManufactureSearchModel model)
|
||||
{
|
||||
@ -47,9 +47,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Manufactures
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) &&
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) &&
|
||||
x.ManufactureName == model.ManufactureName) ||
|
||||
(model.Id.HasValue && x.Id ==
|
||||
model.Id))
|
||||
@ -95,8 +95,8 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
var element = context.Manufactures
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
.Include(x => x.Components)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
context.Manufactures.Remove(element);
|
||||
|
@ -3,6 +3,7 @@ using BlacksmithWorkshopContracts.SearchModels;
|
||||
using BlacksmithWorkshopContracts.StoragesContracts;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDatabaseImplement.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,8 +18,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Orders
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Include(x => x.Manufacture)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
@ -28,9 +30,9 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
}
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
return context.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
@ -44,7 +46,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Implements
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
using var context = new BlacksmithWorkshopDataBase();
|
||||
var newOrder = Order.Create(context, model);
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
namespace BlacksmithWorkshopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(BlacksmithWorkshopDataBase))]
|
||||
[Migration("20240313061254_InitialCreate")]
|
||||
[Migration("20240324164611_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
/// <inheritdoc />
|
||||
@ -145,11 +145,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
|
||||
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ManufactureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Manufacture");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
|
@ -142,11 +142,13 @@ namespace BlacksmithWorkshopDatabaseImplement.Migrations
|
||||
|
||||
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", null)
|
||||
b.HasOne("BlacksmithWorkshopDatabaseImplement.Models.Manufacture", "Manufacture")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ManufactureId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Manufacture");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BlacksmithWorkshopDatabaseImplement.Models.Component", b =>
|
||||
|
@ -27,7 +27,7 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
|
||||
public int ManufactureId { get; private set; }
|
||||
public virtual Manufacture Manufacture { get; set; } = new();
|
||||
|
||||
public static Order? Create(BlacksmithWorkshopDataBase context, OrderBindingModel model)
|
||||
public static Order? Create(OrderBindingModel model)
|
||||
{
|
||||
return new Order()
|
||||
{
|
||||
@ -38,7 +38,6 @@ namespace BlacksmithWorkshopDatabaseImplement.Models
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
ManufactureId = model.ManufactureId,
|
||||
Manufacture = context.Manufactures.First(y => y.Id == model.ManufactureId)
|
||||
};
|
||||
}
|
||||
public void Update(OrderBindingModel? model)
|
||||
|
Loading…
Reference in New Issue
Block a user