add FileImplement and DatabaseImplement
This commit is contained in:
parent
93d4ff0c66
commit
d74d872e8a
@ -4,5 +4,6 @@
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? ImplementerFIO { get; set; }
|
public string? ImplementerFIO { get; set; }
|
||||||
|
public string? Password { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,6 @@ namespace FlowerShopContracts.SearchModels
|
|||||||
public int? ImplementerId { get; set; }
|
public int? ImplementerId { get; set; }
|
||||||
public DateTime? DateFrom { get; set; }
|
public DateTime? DateFrom { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public DateTime? DateTo { get; set; }
|
||||||
public OrderStatus Status { get; set; }
|
public OrderStatus? Status { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,5 +20,6 @@ namespace FlowerShopDatabaseImplement
|
|||||||
public virtual DbSet<FlowerComponent> FlowerComponents { set; get; }
|
public virtual DbSet<FlowerComponent> FlowerComponents { set; get; }
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
public virtual DbSet<Client> Clients { set; get; }
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,90 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var Context = new FlowerShopDatabase();
|
||||||
|
|
||||||
|
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 FlowerShopDatabase();
|
||||||
|
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 FlowerShopDatabase();
|
||||||
|
|
||||||
|
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 FlowerShopDatabase();
|
||||||
|
|
||||||
|
Context.Implementers.Add(NewImplementer);
|
||||||
|
Context.SaveChanges();
|
||||||
|
|
||||||
|
return NewImplementer.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
using var Context = new FlowerShopDatabase();
|
||||||
|
|
||||||
|
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 FlowerShopDatabase();
|
||||||
|
|
||||||
|
var Implementer = Context.Implementers.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (Implementer == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Context.Implementers.Remove(Implementer);
|
||||||
|
Context.SaveChanges();
|
||||||
|
|
||||||
|
return Implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -29,7 +29,9 @@ namespace FlowerShopDatabaseImplement.Implements
|
|||||||
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|
||||||
|| (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
|| (model.ClientId.HasValue && x.ClientId == model.ClientId)
|
||||||
|
|| (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId)
|
||||||
|
|| (model.Status.HasValue && x.Status == model.Status))
|
||||||
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
.Select(x => AccessFlowerStorage(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
56
FlowerShop/FlowerShopDatabaseImplement/Models/Implementer.cs
Normal file
56
FlowerShop/FlowerShopDatabaseImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopDatabaseImplement.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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ namespace FlowerShopDatabaseImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int FlowerId { get; private set; }
|
public int FlowerId { get; private set; }
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
public int ImplementerId { get; private set; }
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
[Required]
|
[Required]
|
||||||
|
@ -10,10 +10,12 @@ namespace FlowerShopFileImplement
|
|||||||
private readonly string OrderFileName = "Order.xml";
|
private readonly string OrderFileName = "Order.xml";
|
||||||
private readonly string FlowerFileName = "Flower.xml";
|
private readonly string FlowerFileName = "Flower.xml";
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
|
private readonly string ImplementerFileName = "Implementer.xml"
|
||||||
public List<Component> Components { get; private set; }
|
public List<Component> Components { get; private set; }
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
public List<Flower> Flowers { get; private set; }
|
public List<Flower> Flowers { get; private set; }
|
||||||
public List<Client> Clients { get; private set; }
|
public List<Client> Clients { get; private set; }
|
||||||
|
public List<Implementer> Implementers { get; private set; }
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -26,12 +28,14 @@ namespace FlowerShopFileImplement
|
|||||||
public void SaveFlowers() => SaveData(Flowers, FlowerFileName, "Flowers", x => x.GetXElement);
|
public void SaveFlowers() => SaveData(Flowers, FlowerFileName, "Flowers", x => x.GetXElement);
|
||||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
|
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
|
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!);
|
||||||
}
|
}
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton _source;
|
||||||
|
|
||||||
|
public ImplementerStorage()
|
||||||
|
{
|
||||||
|
_source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return _source.Implementers.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel Model)
|
||||||
|
{
|
||||||
|
if (Model == null)
|
||||||
|
return new();
|
||||||
|
|
||||||
|
if (Model.Id.HasValue)
|
||||||
|
{
|
||||||
|
var Res = GetElement(Model);
|
||||||
|
return Res != null ? new() { Res } : new();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Model.ImplementerFIO != null)
|
||||||
|
{
|
||||||
|
return _source.Implementers
|
||||||
|
.Where(x => x.ImplementerFIO.Equals(Model.ImplementerFIO))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue)
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
|
||||||
|
if (model.ImplementerFIO != null && model.Password != null)
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO) && x.Password.Equals(model.Password))?.GetViewModel;
|
||||||
|
|
||||||
|
if (model.ImplementerFIO != null)
|
||||||
|
return _source.Implementers.FirstOrDefault(x => x.ImplementerFIO.Equals(model.ImplementerFIO))?.GetViewModel;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = _source.Implementers.Count > 0 ? _source.Implementers.Max(x => x.Id) + 1 : 1;
|
||||||
|
|
||||||
|
var Res = Implementer.Create(model);
|
||||||
|
if (Res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Add(Res);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Res?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
var Res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Res != null)
|
||||||
|
{
|
||||||
|
Res.Update(model);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Res?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
var Res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Res != null)
|
||||||
|
{
|
||||||
|
_source.Implementers.Remove(Res);
|
||||||
|
_source.SaveImplementers();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Res?.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -22,12 +22,16 @@ namespace FlowerShopFileImplement.Implements
|
|||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
{
|
{
|
||||||
return source.Orders
|
return source.Orders
|
||||||
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) && (!model.ClientId.HasValue || x.ClientId == model.ClientId))
|
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||||
|
&& (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId))
|
||||||
.Select(GetViewModel)
|
.Select(GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
return source.Orders
|
return source.Orders
|
||||||
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
.Where(x => (model.Id.HasValue && x.Id == model.Id)
|
||||||
|
|| (model.ClientId.HasValue && x.ClientId == model.ClientId)
|
||||||
|
|| (model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId))
|
||||||
.Select(GetViewModel)
|
.Select(GetViewModel)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
70
FlowerShop/FlowerShopFileImplement/Models/Implementer.cs
Normal file
70
FlowerShop/FlowerShopFileImplement/Models/Implementer.cs
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace FlowerShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Implementer : IImplementerModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ImplementerFIO { get; private set; } = string.Empty;
|
||||||
|
public string Password { get; private set; } = string.Empty;
|
||||||
|
public int WorkExperience { get; private set; }
|
||||||
|
public int Qualification { get; private set; }
|
||||||
|
public static Implementer? Create(ImplementerBindingModel Model)
|
||||||
|
{
|
||||||
|
if (Model == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Model.Id,
|
||||||
|
ImplementerFIO = Model.ImplementerFIO,
|
||||||
|
Password = Model.Password,
|
||||||
|
WorkExperience = Model.WorkExperience,
|
||||||
|
Qualification = Model.Qualification,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Implementer? Create(XElement Element)
|
||||||
|
{
|
||||||
|
if (Element == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||||
|
ImplementerFIO = Element.Element("ImplementerFIO")!.Value,
|
||||||
|
Password = Element.Element("Password")!.Value,
|
||||||
|
WorkExperience = Convert.ToInt32(Element.Element("WorkExperience")!.Value),
|
||||||
|
Qualification = Convert.ToInt32(Element.Element("Qualification")!.Value),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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,
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new(
|
||||||
|
"Implementer",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ImplementerFIO", ImplementerFIO),
|
||||||
|
new XElement("Password", Password),
|
||||||
|
new XElement("WorkExperience", WorkExperience),
|
||||||
|
new XElement("Qualification", Qualification)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -11,6 +11,7 @@ namespace FlowerShopFileImplement.Models
|
|||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
public int FlowerId { get; private set; }
|
public int FlowerId { get; private set; }
|
||||||
public int ClientId { get; private set; }
|
public int ClientId { get; private set; }
|
||||||
|
public int ImplementerId { get; private set; }
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
public OrderStatus Status { get; set; }
|
public OrderStatus Status { get; set; }
|
||||||
@ -27,6 +28,7 @@ namespace FlowerShopFileImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
FlowerId = model.FlowerId,
|
FlowerId = model.FlowerId,
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
|
ImplementerId = model.ImplementerId,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
@ -45,6 +47,7 @@ namespace FlowerShopFileImplement.Models
|
|||||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
FlowerId = Convert.ToInt32(element.Element("FlowerId")!.Value),
|
FlowerId = Convert.ToInt32(element.Element("FlowerId")!.Value),
|
||||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
|
||||||
|
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
|
||||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
Status = (OrderStatus) Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
Status = (OrderStatus) Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||||
@ -61,6 +64,7 @@ namespace FlowerShopFileImplement.Models
|
|||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
FlowerId = model.FlowerId;
|
FlowerId = model.FlowerId;
|
||||||
ClientId = model.ClientId;
|
ClientId = model.ClientId;
|
||||||
|
ImplementerId = model.ImplementerId;
|
||||||
Count = model.Count;
|
Count = model.Count;
|
||||||
Sum = model.Sum;
|
Sum = model.Sum;
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
@ -72,6 +76,7 @@ namespace FlowerShopFileImplement.Models
|
|||||||
Id = Id,
|
Id = Id,
|
||||||
FlowerId = FlowerId,
|
FlowerId = FlowerId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
|
ImplementerId = ImplementerId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
Status = Status,
|
Status = Status,
|
||||||
@ -83,7 +88,8 @@ namespace FlowerShopFileImplement.Models
|
|||||||
new XAttribute("Id", Id),
|
new XAttribute("Id", Id),
|
||||||
new XElement("FlowerId", FlowerId.ToString()),
|
new XElement("FlowerId", FlowerId.ToString()),
|
||||||
new XElement("ClientId", ClientId.ToString()),
|
new XElement("ClientId", ClientId.ToString()),
|
||||||
new XElement("Count", Count.ToString()),
|
new XElement("ImplementerId", ImplementerId.ToString()),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
new XElement("Sum", Sum.ToString()),
|
new XElement("Sum", Sum.ToString()),
|
||||||
new XElement("Status", Status.ToString()),
|
new XElement("Status", Status.ToString()),
|
||||||
new XElement("DateCreate", DateCreate.ToString()),
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
@ -0,0 +1,104 @@
|
|||||||
|
using FlowerShopContracts.BindingModels;
|
||||||
|
using FlowerShopContracts.SearchModels;
|
||||||
|
using FlowerShopContracts.StoragesContracts;
|
||||||
|
using FlowerShopContracts.ViewModels;
|
||||||
|
using FlowerShopListImplement.Models;
|
||||||
|
|
||||||
|
namespace FlowerShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class ImplementerStorage : IImplementerStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public ImplementerStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImplementerViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var Result = new List<ImplementerViewModel>();
|
||||||
|
|
||||||
|
foreach (var Implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
Result.Add(Implementer.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ImplementerFIO))
|
||||||
|
return new();
|
||||||
|
|
||||||
|
return _source.Implementers
|
||||||
|
.Where(x => (!string.IsNullOrEmpty(model.ImplementerFIO) && x.ImplementerFIO.Contains(model.ImplementerFIO)))
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
|
||||||
|
{
|
||||||
|
foreach (var Implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if ((model.Id.HasValue && Implementer.Id == model.Id) ||
|
||||||
|
(!string.IsNullOrEmpty(model.ImplementerFIO) && Implementer.ImplementerFIO == model.ImplementerFIO))
|
||||||
|
{
|
||||||
|
return Implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Insert(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var Implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (model.Id <= Implementer.Id)
|
||||||
|
{
|
||||||
|
model.Id = Implementer.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var NewImplementer = Implementer.Create(model);
|
||||||
|
if (NewImplementer == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
_source.Implementers.Add(NewImplementer);
|
||||||
|
return NewImplementer.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Update(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var Implementer in _source.Implementers)
|
||||||
|
{
|
||||||
|
if (Implementer.Id == model.Id)
|
||||||
|
{
|
||||||
|
Implementer.Update(model);
|
||||||
|
return Implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImplementerViewModel? Delete(ImplementerBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Implementers.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Implementers[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var Implementer = _source.Implementers[i];
|
||||||
|
_source.Implementers.RemoveAt(i);
|
||||||
|
|
||||||
|
return Implementer.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,12 +28,16 @@ namespace FlowerShopListImplement.Implements
|
|||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
{
|
{
|
||||||
return _source.Orders
|
return _source.Orders
|
||||||
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) && (!model.ClientId.HasValue || x.ClientId == model.ClientId))
|
.Where(x => (x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||||
|
&& (!model.ClientId.HasValue || x.ClientId == model.ClientId)
|
||||||
|
&& (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId))
|
||||||
.Select(x => AttachNames(x.GetViewModel))
|
.Select(x => AttachNames(x.GetViewModel))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
return _source.Orders
|
return _source.Orders
|
||||||
.Where(x => (model.Id.HasValue && x.Id == model.Id) || (model.ClientId.HasValue && x.ClientId == model.ClientId))
|
.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 => AttachNames(x.GetViewModel))
|
.Select(x => AttachNames(x.GetViewModel))
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user