Надежда
This commit is contained in:
parent
be264cb02b
commit
d696e4d6b7
@ -92,11 +92,11 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.RepairName))
|
if (string.IsNullOrEmpty(model.RepairName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Нет названия компьютера", nameof(model.RepairName));
|
throw new ArgumentNullException("Нет названия ремонта", nameof(model.RepairName));
|
||||||
}
|
}
|
||||||
if (model.Price <= 0)
|
if (model.Price <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Цена компьютера должна быть больше 0", nameof(model.Price));
|
throw new ArgumentNullException("Цена ремонта должна быть больше 0", nameof(model.Price));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Repair. RepairName:{RepairName}.Price:{ Price}. Id: { Id} ", model.RepairName, model.Price, model.Id);
|
_logger.LogInformation("Repair. RepairName:{RepairName}.Price:{ Price}. Id: { Id} ", model.RepairName, model.Price, model.Id);
|
||||||
var element = _repairStorage.GetElement(new RepairSearchModel
|
var element = _repairStorage.GetElement(new RepairSearchModel
|
||||||
@ -105,7 +105,7 @@ namespace RenovationWorkBusinessLogic.BusinessLogics
|
|||||||
});
|
});
|
||||||
if (element != null && element.Id != model.Id)
|
if (element != null && element.Id != model.Id)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException("Компьютер с таким названием уже есть");
|
throw new InvalidOperationException("Ремонт с таким названием уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,7 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
public List<ComponentViewModel> GetFullList()
|
public List<ComponentViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Components
|
return context.Components.Select(x => x.GetViewModel).ToList();
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
{
|
{
|
||||||
@ -23,10 +21,7 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Components
|
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)
|
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||||
{
|
{
|
||||||
@ -35,11 +30,7 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Components
|
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)
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
{
|
{
|
||||||
@ -69,13 +60,13 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
context.Components.Remove(element);
|
return null;
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
}
|
||||||
return null;
|
context.Components.Remove(element);
|
||||||
|
context.SaveChanges();
|
||||||
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,84 +11,76 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var Context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
|
return context.Orders.Include(x => x.Repair).Select(x => x.GetViewModel).ToList();
|
||||||
return Context.Orders
|
|
||||||
.Include(x => x.Repair)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel Model)
|
|
||||||
{
|
{
|
||||||
if (!Model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
return new();
|
return new();
|
||||||
|
}
|
||||||
using var Context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
|
return context.Orders
|
||||||
return Context.Orders
|
.Include(x => x.Repair)
|
||||||
.Include(x => x.Repair)
|
.Where(x => x.Id == model.Id)
|
||||||
.Where(x => x.Id == Model.Id)
|
.Select(x => x.GetViewModel)
|
||||||
.Select(x => x.GetViewModel)
|
.ToList();
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
public OrderViewModel? GetElement(OrderSearchModel Model)
|
|
||||||
{
|
{
|
||||||
if (!Model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
return new();
|
{
|
||||||
|
return null;
|
||||||
using var Context = new RenovationWorkDatabase();
|
}
|
||||||
|
using var context = new RenovationWorkDatabase();
|
||||||
return Context.Orders
|
return context.Orders.Include(x => x.Repair)
|
||||||
.Include(x => x.Repair)
|
.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
.FirstOrDefault(x => x.Id == Model.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
public OrderViewModel? Insert(OrderBindingModel Model)
|
|
||||||
{
|
{
|
||||||
using var Context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
|
if (model == null)
|
||||||
if (Model == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
var newOrder = Order.Create(context, model);
|
||||||
var NewOrder = Order.Create(Context, Model);
|
if (newOrder == null)
|
||||||
if (NewOrder == null)
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
Context.Orders.Add(NewOrder);
|
context.Orders.Add(newOrder);
|
||||||
Context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
return newOrder.GetViewModel;
|
||||||
return NewOrder.GetViewModel;
|
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
public OrderViewModel? Update(OrderBindingModel Model)
|
|
||||||
{
|
{
|
||||||
using var Context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
|
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
var Order = Context.Orders.FirstOrDefault(x => x.Id == Model.Id);
|
if (order == null)
|
||||||
if (Order == null)
|
{
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
Order.Update(Model);
|
order.Update(model);
|
||||||
Context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
return context.Orders
|
||||||
return Order.GetViewModel;
|
.Include(x => x.Repair)
|
||||||
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
|
||||||
{
|
{
|
||||||
using var Context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
var Order = Context.Orders.FirstOrDefault(rec => rec.Id == Model.Id);
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
if (Order == null)
|
{
|
||||||
return null;
|
var deletedElement = context.Orders
|
||||||
|
.Include(x => x.Repair)
|
||||||
Context.Orders.Remove(Order);
|
.FirstOrDefault(x => x.Id == model.Id)
|
||||||
Context.SaveChanges();
|
?.GetViewModel;
|
||||||
|
context.Orders.Remove(element);
|
||||||
return Order.GetViewModel;
|
context.SaveChanges();
|
||||||
|
return deletedElement;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,7 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
public List<RepairViewModel> GetFullList()
|
public List<RepairViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Repairs
|
return context.Repairs.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<RepairViewModel> GetFilteredList(RepairSearchModel model)
|
public List<RepairViewModel> GetFilteredList(RepairSearchModel model)
|
||||||
{
|
{
|
||||||
@ -25,13 +20,8 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
return new();
|
return new();
|
||||||
}
|
}
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Repairs
|
return context.Repairs.Include(x => x.Components).ThenInclude(x => x.Component).Where(x => x.RepairName.Contains(model.RepairName)).ToList().Select(x => x.GetViewModel).ToList();
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.Where(x => x.RepairName.Contains(model.RepairName))
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
public RepairViewModel? GetElement(RepairSearchModel model)
|
public RepairViewModel? GetElement(RepairSearchModel model)
|
||||||
{
|
{
|
||||||
@ -41,24 +31,20 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
return context.Repairs
|
return context.Repairs.Include(x => x.Components).ThenInclude(x => x.Component)
|
||||||
.Include(x => x.Components)
|
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) && x.RepairName == model.RepairName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.RepairName) &&
|
|
||||||
x.RepairName == model.RepairName) ||
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
|
||||||
}
|
}
|
||||||
public RepairViewModel? Insert(RepairBindingModel model)
|
public RepairViewModel? Insert(RepairBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new RenovationWorkDatabase();
|
using var context = new RenovationWorkDatabase();
|
||||||
var newRepair = Repair.Create(context, model);
|
var newEngine = Repair.Create(context, model);
|
||||||
if (newRepair == null)
|
if (newEngine == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
context.Repairs.Add(newRepair);
|
context.Repairs.Add(newEngine);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return newRepair.GetViewModel;
|
return newEngine.GetViewModel;
|
||||||
}
|
}
|
||||||
public RepairViewModel? Update(RepairBindingModel model)
|
public RepairViewModel? Update(RepairBindingModel model)
|
||||||
{
|
{
|
||||||
@ -66,17 +52,17 @@ namespace RenovationWorkDatabaseImplement.Implements
|
|||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var repair = context.Repairs.FirstOrDefault(rec =>
|
var engine = context.Repairs.FirstOrDefault(rec =>
|
||||||
rec.Id == model.Id);
|
rec.Id == model.Id);
|
||||||
if (repair == null)
|
if (engine == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
repair.Update(model);
|
engine.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
repair.UpdateComponents(context, model);
|
engine.UpdateComponents(context, model);
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return repair.GetViewModel;
|
return engine.GetViewModel;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ using RenovationWorkDatabaseImplement;
|
|||||||
namespace RenovationWorkDatabaseImplement.Migrations
|
namespace RenovationWorkDatabaseImplement.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(RenovationWorkDatabase))]
|
[DbContext(typeof(RenovationWorkDatabase))]
|
||||||
[Migration("20240405063901_InitialCreate")]
|
[Migration("20240418122550_InitialCreate")]
|
||||||
partial class InitialCreate
|
partial class InitialCreate
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
@ -27,7 +27,7 @@ namespace RenovationWorkDatabaseImplement.Models
|
|||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new Component()
|
return new Component
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ComponentName = model.ComponentName,
|
ComponentName = model.ComponentName,
|
||||||
@ -58,6 +58,5 @@ namespace RenovationWorkDatabaseImplement.Models
|
|||||||
ComponentName = ComponentName,
|
ComponentName = ComponentName,
|
||||||
Cost = Cost
|
Cost = Cost
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,17 +35,18 @@ namespace RenovationWorkDatabaseImplement.Models
|
|||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
public static Order Create(RenovationWorkDatabase context, OrderBindingModel Model)
|
public static Order Create(RenovationWorkDatabase context, OrderBindingModel model)
|
||||||
{
|
{
|
||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = Model.Id,
|
Id = model.Id,
|
||||||
RepairId = Model.RepairId,
|
RepairId = model.RepairId,
|
||||||
Count = Model.Count,
|
Repair = context.Repairs.First(x => x.Id == model.RepairId),
|
||||||
Sum = Model.Sum,
|
Count = model.Count,
|
||||||
Status = Model.Status,
|
Sum = model.Sum,
|
||||||
DateCreate = Model.DateCreate,
|
Status = model.Status,
|
||||||
DateImplement = Model.DateImplement,
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,11 +55,7 @@ namespace RenovationWorkDatabaseImplement.Models
|
|||||||
if (Model == null)
|
if (Model == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Id = Model.Id;
|
|
||||||
RepairId = Model.RepairId;
|
|
||||||
Sum = Model.Sum;
|
|
||||||
Status = Model.Status;
|
Status = Model.Status;
|
||||||
DateCreate = Model.DateCreate;
|
|
||||||
DateImplement = Model.DateImplement;
|
DateImplement = Model.DateImplement;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user