PIbd-21 Lab6 KozyrevSS SewingDresses #19

Closed
Serxionaft wants to merge 10 commits from Lab6 into Lab5Magic
8 changed files with 328 additions and 4 deletions
Showing only changes of commit 345bd3a5f6 - Show all commits

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace SewingDressesBusinessLogic.BusinessLogic
{
public class ImplementLogic //: IImplementLogic
public class ImplementLogic : IImplementLogic
{
private readonly ILogger _logger;
private readonly IImplementStorage _storage;

View File

@ -10,10 +10,12 @@ namespace SewingDressesFileImplement
private readonly string OrderFileName = "Order.xml";
private readonly string DressFileName = "Dress.xml";
private readonly string ClientFileName = "Client.xml";
public List<Component> Components { get; private set; }
private readonly string ImplementFileName = "Implement.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<Dress> Dresses { get; private set;}
public List<Client> Clients { get; private set; }
public List<Implement> Implements { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@ -42,12 +44,14 @@ namespace SewingDressesFileImplement
public void SaveDresses() => SaveData(Dresses, DressFileName, "Dresses", 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 SaveImplements() => SaveData(Implements, ImplementFileName, "Implements", x => x.GetXElement);
private DataFileSingleton()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Dresses = LoadData(DressFileName, "Dress", x => Dress.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
Implements = LoadData(ImplementFileName, "Implement", x => Implement.Create(x)!)!;
}
}
}

View File

@ -0,0 +1,77 @@
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.ViewModels;
using SewingDressesFileImplement.Models;
namespace SewingDressesFileImplement.Implements
{
public class ImplementStorage : IImplementStorage
{
private readonly DataFileSingleton source;
public ImplementStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ImplementViewModel> GetFullList()
{
return source.Implements
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel model)
{
if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password))
{
return new();
}
return source.Implements
.Where(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO.Contains(model.ImplementFIO)) &&
(string.IsNullOrEmpty(model.Password) || x.Password.Contains(model.Password)))
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementViewModel? GetElement(ImplementSearchModel model)
{
return source.Implements
.FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementFIO) || x.ImplementFIO == model.ImplementFIO) &&
(!model.Id.HasValue || x.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || x.Password == model.Password))
?.GetViewModel;
}
public ImplementViewModel? Insert(ImplementBindingModel model)
{
model.Id = source.Implements.Count > 0 ? source.Implements.Max(x =>
x.Id) + 1 : 1;
var newImplement = Implement.Create(model);
if (newImplement == null)
{
return null;
}
source.Implements.Add(newImplement);
source.SaveImplements();
return newImplement.GetViewModel;
}
public ImplementViewModel? Update(ImplementBindingModel model)
{
var Implement = source.Implements.FirstOrDefault(x => x.Id == model.Id);
if (Implement == null)
{
return null;
}
Implement.Update(model);
source.SaveImplements();
return Implement.GetViewModel;
}
public ImplementViewModel? Delete(ImplementBindingModel model)
{
var element = source.Implements.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
source.Implements.Remove(element);
source.SaveImplements();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,76 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace SewingDressesFileImplement.Models
{
public class Implement : IImplementModel
{
public int Id { get; set; }
public string ImplementFIO { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
public static Implement? Create(ImplementBindingModel? model)
{
if (model == null) return null;
return new Implement
{
Id = model.Id,
ImplementFIO = model.ImplementFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification,
};
}
public static Implement? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Implement()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ImplementFIO = element.Element("ImplementFIO")!.Value,
Password = element.Element("Password")!.Value,
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value)
};
}
public XElement GetXElement => new("Implement",
new XAttribute("Id", Id),
new XElement("ImplementFIO", ImplementFIO),
new XElement("Password", Password),
new XElement("Qualification", Qualification.ToString()),
new XElement("WorkExperience", WorkExperience.ToString())
);
public ImplementViewModel GetViewModel => new()
{
Id = Id,
ImplementFIO = ImplementFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
public void Update(ImplementBindingModel model)
{
if (model == null)
{
return;
}
ImplementFIO = model.ImplementFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
}
}

View File

@ -29,6 +29,8 @@ namespace SewingDressesFileImplement.Models
{
Id = model.Id,
DressId = model.DressId,
ClientId = model.ClientId,
ImplementId = model.ImplementId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
@ -46,7 +48,9 @@ namespace SewingDressesFileImplement.Models
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
DressId = Convert.ToInt32(element.Element("DressId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value),
ImplementId = Convert.ToInt32(element.Element("ImplementId")?.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value, new System.Globalization.CultureInfo("en-US")),
Status = (OrderStatus)Convert.ToInt32(element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")?.Value),
@ -66,6 +70,8 @@ namespace SewingDressesFileImplement.Models
{
Id = Id,
DressId = DressId,
ClientId = ClientId,
ImplementId = ImplementId,
Count = Count,
Sum = Sum,
Status = Status,
@ -75,7 +81,9 @@ namespace SewingDressesFileImplement.Models
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("DressId", DressId),
new XElement("Count", Count),
new XElement("ClientId", ClientId),
new XElement("ImplementId", ImplementId),
new XElement("Count", Count),
new XElement("Sum", Sum),
new XElement("Status", Status - OrderStatus.Принят),
new XElement("DateCreate", DateCreate),

View File

@ -9,12 +9,14 @@ namespace SewingDressesListImplement
public List<Order> Orders { get; set; }
public List<Dress> Dresses { get; set; }
public List<Client> Clients { get; set; }
public List<Implement> Implements { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Dresses = new List<Dress>();
Clients = new List<Client>();
Implements = new List<Implement>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,103 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.SearchModels;
using SewingDressesContracts.StoragesContracts;
using SewingDressesContracts.ViewModels;
using SewingDressesListImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesListImplement.Implements
{
public class ImplementStorage : IImplementStorage
{
private readonly DataListSingleton _source;
public ImplementStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<ImplementViewModel> GetFullList()
{
var result = new List<ImplementViewModel>();
foreach (var Implement in _source.Implements)
{
result.Add(Implement.GetViewModel);
}
return result;
}
public List<ImplementViewModel> GetFilteredList(ImplementSearchModel
model)
{
var result = new List<ImplementViewModel>();
if (string.IsNullOrEmpty(model.ImplementFIO) && string.IsNullOrEmpty(model.Password))
{
return result;
}
foreach (var Implement in _source.Implements)
{
if (Implement.ImplementFIO.Contains(model.ImplementFIO))
{
result.Add(Implement.GetViewModel);
}
}
return result;
}
public ImplementViewModel? GetElement(ImplementSearchModel model)
{
foreach (var Implement in _source.Implements)
{
if ((string.IsNullOrEmpty(model.ImplementFIO) || Implement.ImplementFIO == model.ImplementFIO) &&
(!model.Id.HasValue || Implement.Id == model.Id) && (string.IsNullOrEmpty(model.Password) || Implement.Password == model.Password))
{
return Implement.GetViewModel;
}
}
return null;
}
public ImplementViewModel? Insert(ImplementBindingModel model)
{
model.Id = 1;
foreach (var Implement in _source.Implements)
{
if (model.Id <= Implement.Id)
{
model.Id = Implement.Id + 1;
}
}
var newImplement = Implement.Create(model);
if (newImplement == null)
{
return null;
}
_source.Implements.Add(newImplement);
return newImplement.GetViewModel;
}
public ImplementViewModel? Update(ImplementBindingModel model)
{
foreach (var Implement in _source.Implements)
{
if (model.Id == Implement.Id)
{
Implement.Update(model);
return Implement.GetViewModel;
}
}
return null;
}
public ImplementViewModel? Delete(ImplementBindingModel model)
{
for (int i = 0; i < _source.Implements.Count; ++i)
{
if (_source.Implements[i].Id == model.Id)
{
var element = _source.Implements[i];
_source.Implements.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,54 @@
using SewingDressesContracts.BindingModels;
using SewingDressesContracts.ViewModels;
using SewingDressesDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewingDressesListImplement.Models
{
public class Implement : IImplementModel
{
public int Id { get; private set; }
public string ImplementFIO { get; private set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; } = 0;
public int Qualification { get; set; } = 0;
public static Implement? Create(ImplementBindingModel model)
{
if (model == null)
{
return null;
}
return new Implement()
{
Id = model.Id,
ImplementFIO = model.ImplementFIO,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public void Update(ImplementBindingModel model)
{
if (model == null)
{
return;
}
ImplementFIO = model.ImplementFIO;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementViewModel GetViewModel => new()
{
Id = Id,
ImplementFIO = ImplementFIO,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
}
}