Созданы классы хранилищ
This commit is contained in:
parent
791ab703b2
commit
eabc9c7415
33
LawFirm/LawFirmListImplements/DataListSingleton.cs
Normal file
33
LawFirm/LawFirmListImplements/DataListSingleton.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using LawFirmListImplements.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplements
|
||||||
|
{
|
||||||
|
public class DataListSingleton
|
||||||
|
{
|
||||||
|
private static DataListSingleton? _instance;
|
||||||
|
public List<Blank> Blanks { get; set; }
|
||||||
|
public List<Order> Orders { get; set; }
|
||||||
|
public List<Document> Documents { get; set; }
|
||||||
|
private DataListSingleton()
|
||||||
|
{
|
||||||
|
Blanks = new List<Blank>();
|
||||||
|
Orders = new List<Order>();
|
||||||
|
Documents = new List<Document>();
|
||||||
|
}
|
||||||
|
public static DataListSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (_instance == null)
|
||||||
|
{
|
||||||
|
_instance = new DataListSingleton();
|
||||||
|
}
|
||||||
|
return _instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
112
LawFirm/LawFirmListImplements/Implements/BlankStorage.cs
Normal file
112
LawFirm/LawFirmListImplements/Implements/BlankStorage.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmListImplements.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplements.Implements
|
||||||
|
{
|
||||||
|
public class BlankStorage : IBlankStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public BlankStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlankViewModel? GetElement(BlankSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var blank in _source.Blanks)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.BlankName) && blank.BlankName == model.BlankName) || (model.Id.HasValue && blank.Id == model.Id))
|
||||||
|
{
|
||||||
|
return blank.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<BlankViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.BlankName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var blank in _source.Blanks)
|
||||||
|
{
|
||||||
|
if (blank.BlankName.Contains(model.BlankName))
|
||||||
|
{
|
||||||
|
result.Add(blank.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BlankViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<BlankViewModel>();
|
||||||
|
foreach (var blank in _source.Blanks)
|
||||||
|
{
|
||||||
|
result.Add(blank.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlankViewModel? Insert(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var blank in _source.Blanks)
|
||||||
|
{
|
||||||
|
if (model.Id <= blank.Id)
|
||||||
|
{
|
||||||
|
model.Id = blank.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newBlank = Blank.Create(model);
|
||||||
|
if (newBlank == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Blanks.Add(newBlank);
|
||||||
|
return newBlank.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BlankViewModel? Update(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var blank in _source.Blanks)
|
||||||
|
{
|
||||||
|
if (blank.Id == model.Id)
|
||||||
|
{
|
||||||
|
blank.Update(model);
|
||||||
|
return blank.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public BlankViewModel? Delete(BlankBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Blanks.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Blanks[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Blanks[i];
|
||||||
|
_source.Blanks.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
110
LawFirm/LawFirmListImplements/Implements/DocumentStorage.cs
Normal file
110
LawFirm/LawFirmListImplements/Implements/DocumentStorage.cs
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmListImplements.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplements.Implements
|
||||||
|
{
|
||||||
|
public class DocumentStorage : IDocumentStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public DocumentStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public DocumentViewModel? GetElement(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var document in _source.Documents)
|
||||||
|
{
|
||||||
|
if ((!string.IsNullOrEmpty(model.DocumentName) && document.DocumentName == model.DocumentName) || (model.Id.HasValue && document.Id == model.Id))
|
||||||
|
{
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<DocumentViewModel>();
|
||||||
|
if (string.IsNullOrEmpty(model.DocumentName))
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var document in _source.Documents)
|
||||||
|
{
|
||||||
|
if (document.DocumentName.Contains(model.DocumentName))
|
||||||
|
{
|
||||||
|
result.Add(document.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DocumentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<DocumentViewModel>();
|
||||||
|
foreach (var document in _source.Documents)
|
||||||
|
{
|
||||||
|
result.Add(document.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentViewModel? Insert(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var document in _source.Documents)
|
||||||
|
{
|
||||||
|
if (model.Id <= document.Id)
|
||||||
|
{
|
||||||
|
model.Id = document.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newDoc = Document.Create(model);
|
||||||
|
if (newDoc == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Documents.Add(newDoc);
|
||||||
|
return newDoc.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentViewModel? Update(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var document in _source.Documents)
|
||||||
|
{
|
||||||
|
if (document.Id == model.Id)
|
||||||
|
{
|
||||||
|
document.Update(model);
|
||||||
|
return document.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public DocumentViewModel? Delete(DocumentBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Documents.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Documents[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Documents[i];
|
||||||
|
_source.Documents.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
112
LawFirm/LawFirmListImplements/Implements/OrderStorage.cs
Normal file
112
LawFirm/LawFirmListImplements/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
using LawFirmContracts.BindingModels;
|
||||||
|
using LawFirmContracts.SearchModels;
|
||||||
|
using LawFirmContracts.StorageContracts;
|
||||||
|
using LawFirmContracts.ViewModels;
|
||||||
|
using LawFirmListImplements.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LawFirmListImplements.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id.HasValue && order.Id == model.Id)
|
||||||
|
{
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
result.Add(order.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<OrderViewModel>();
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
result.Add(order.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = 1;
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (model.Id <= order.Id)
|
||||||
|
{
|
||||||
|
model.Id = order.Id + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Orders.Add(newOrder);
|
||||||
|
return newOrder.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
foreach (var order in _source.Orders)
|
||||||
|
{
|
||||||
|
if (order.Id == model.Id)
|
||||||
|
{
|
||||||
|
order.Update(model);
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
|
{
|
||||||
|
if (_source.Orders[i].Id == model.Id)
|
||||||
|
{
|
||||||
|
var element = _source.Orders[i];
|
||||||
|
_source.Orders.RemoveAt(i);
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -59,7 +59,7 @@ namespace LawFirmListImplements.Models
|
|||||||
Id = model.Id;
|
Id = model.Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel GetViewModel() => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
DocumentId = DocumentId,
|
DocumentId = DocumentId,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user