DatabaseImplement
This commit is contained in:
parent
3a5157069b
commit
e3721f13cb
@ -27,5 +27,7 @@ namespace AutoWorkshopDatabaseImplement
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,90 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.SearchModels;
|
||||
using AutoWorkshopContracts.StoragesContracts;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDatabaseImplement.Models;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Implements
|
||||
{
|
||||
public class ImplementerStorage : IImplementerStorage
|
||||
{
|
||||
public List<ImplementerViewModel> GetFullList()
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Implementers.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
return Context.Implementers.Where(x => x.ImplementerFIO.Contains(Model.ImplementerFIO)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ImplementerViewModel? GetElement(ImplementerSearchModel Model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Model.ImplementerFIO) && !Model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
return Context.Implementers.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ImplementerFIO) && x.ImplementerFIO == Model.ImplementerFIO && (!string.IsNullOrEmpty(Model.Password) ? x.Password == Model.Password : true)) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Insert(ImplementerBindingModel Model)
|
||||
{
|
||||
var NewImplementer = Implementer.Create(Model);
|
||||
if (NewImplementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
Context.Implementers.Add(NewImplementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return NewImplementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Update(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(x => x.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Implementer.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
|
||||
public ImplementerViewModel? Delete(ImplementerBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
|
||||
var Implementer = Context.Implementers.FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
if (Implementer == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
Context.Implementers.Remove(Implementer);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Implementer.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -29,6 +30,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.Where(x => (x.DateCreate >= Model.DateFrom && x.DateCreate <= Model.DateTo) && (!Model.ClientId.HasValue || x.ClientId == Model.ClientId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -37,7 +39,9 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId))
|
||||
.Include (x => x.Implementer)
|
||||
.Where(x => (Model.Id.HasValue && x.Id == Model.Id) || (Model.ClientId.HasValue && x.ClientId == Model.ClientId)
|
||||
|| (Model.ImplementerId.HasValue && x.ImplementerId == Model.ImplementerId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -52,6 +56,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
return Context.Orders
|
||||
.Include(x => x.Repair)
|
||||
.Include(x => x.Client)
|
||||
.Include(x => x.Implementer)
|
||||
.FirstOrDefault(x => Model.Id.HasValue && x.Id == Model.Id)?
|
||||
.GetViewModel;
|
||||
}
|
||||
@ -70,7 +75,7 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
Context.Orders.Add(NewOrder);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == NewOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel Model)
|
||||
@ -84,13 +89,13 @@ namespace AutoWorkshopDatabaseImplement.Implements
|
||||
Order.Update(Model);
|
||||
Context.SaveChanges();
|
||||
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
return Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == Model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel Model)
|
||||
{
|
||||
using var Context = new AutoWorkshopDatabase();
|
||||
var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
var Order = Context.Orders.Include(x => x.Repair).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(rec => rec.Id == Model.Id);
|
||||
|
||||
if (Order == null)
|
||||
return null;
|
||||
|
64
AutoWorkshopDatabaseImplement/Models/Implementer.cs
Normal file
64
AutoWorkshopDatabaseImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using AutoWorkshopContracts.BindingModels;
|
||||
using AutoWorkshopContracts.ViewModels;
|
||||
using AutoWorkshopDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace AutoWorkshopDatabaseImplement.Models
|
||||
{
|
||||
public class Implementer : IImplementerModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string ImplementerFIO { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int WorkExperience { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Qualification { get; set; }
|
||||
|
||||
[ForeignKey("ImplementerId")]
|
||||
public virtual List<Order> Order { get; set; } = new();
|
||||
|
||||
public static Implementer? Create(ImplementerBindingModel? Model)
|
||||
{
|
||||
if (Model == null)
|
||||
return null;
|
||||
|
||||
return new Implementer()
|
||||
{
|
||||
Id = Model.Id,
|
||||
ImplementerFIO = Model.ImplementerFIO,
|
||||
Password = Model.Password,
|
||||
WorkExperience = Model.WorkExperience,
|
||||
Qualification = Model.Qualification
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(ImplementerBindingModel Model)
|
||||
{
|
||||
if (Model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ImplementerFIO = Model.ImplementerFIO;
|
||||
Password = Model.Password;
|
||||
WorkExperience = Model.WorkExperience;
|
||||
Qualification = Model.Qualification;
|
||||
}
|
||||
|
||||
public ImplementerViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ImplementerFIO = ImplementerFIO,
|
||||
Password = Password,
|
||||
WorkExperience = WorkExperience,
|
||||
Qualification = Qualification
|
||||
};
|
||||
}
|
||||
}
|
@ -20,6 +20,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public int? ImplementerId { get; private set; }
|
||||
|
||||
public virtual Implementer? Implementer { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -44,6 +48,7 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
Id = Model.Id,
|
||||
RepairId = Model.RepairId,
|
||||
ClientId = Model.ClientId,
|
||||
ImplementerId = Model.ImplementerId,
|
||||
Count = Model.Count,
|
||||
Sum = Model.Sum,
|
||||
Status = Model.Status,
|
||||
@ -57,6 +62,7 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
if (Model is null)
|
||||
return;
|
||||
|
||||
ImplementerId = Model.ImplementerId;
|
||||
Status = Model.Status;
|
||||
DateImplement = Model.DateImplement;
|
||||
}
|
||||
@ -66,8 +72,10 @@ namespace AutoWorkshopDatabaseImplement.Models
|
||||
Id = Id,
|
||||
RepairId = RepairId,
|
||||
ClientId = ClientId,
|
||||
ImplementerId = ImplementerId,
|
||||
RepairName = Repair.RepairName,
|
||||
ClientFIO = Client.ClientFIO,
|
||||
ImplementerFIO = Implementer?.ImplementerFIO,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
Loading…
Reference in New Issue
Block a user