Созданы реализации интерфейсов хранилищ
This commit is contained in:
parent
2d57093fb6
commit
8345b53f15
88
LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs
Normal file
88
LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
public class BlankStorage : IBlankStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public BlankStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public BlankViewModel? GetElement(BlankSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Blanks
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BlankName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Blanks
|
||||
.Where(x => x.BlankName.Contains(model.BlankName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BlankViewModel> GetFullList()
|
||||
{
|
||||
return source.Blanks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public BlankViewModel? Insert(BlankBindingModel model)
|
||||
{
|
||||
model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1;
|
||||
var newBlank = Blank.Create(model);
|
||||
if (newBlank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Blanks.Add(newBlank);
|
||||
source.SaveBlanks();
|
||||
return newBlank.GetViewModel;
|
||||
}
|
||||
|
||||
public BlankViewModel? Update(BlankBindingModel model)
|
||||
{
|
||||
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (blank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
blank.Update(model);
|
||||
source.SaveBlanks();
|
||||
return blank.GetViewModel;
|
||||
}
|
||||
public BlankViewModel? Delete(BlankBindingModel model)
|
||||
{
|
||||
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (blank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
blank.Update(model);
|
||||
source.SaveBlanks();
|
||||
return blank.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
87
LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs
Normal file
87
LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
internal class DocumentStorage : IDocumentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public DocumentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public DocumentViewModel? GetElement(DocumentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Documents
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DocumentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Documents
|
||||
.Where(x => x.DocumentName.Contains(model.DocumentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DocumentViewModel> GetFullList()
|
||||
{
|
||||
return source.Documents.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public DocumentViewModel? Insert(DocumentBindingModel model)
|
||||
{
|
||||
model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1;
|
||||
var newDoc = Document.Create(model);
|
||||
if (newDoc == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Documents.Add(newDoc);
|
||||
source.SaveDocuments();
|
||||
return newDoc.GetViewModel;
|
||||
}
|
||||
|
||||
public DocumentViewModel? Update(DocumentBindingModel model)
|
||||
{
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (document == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
document.Update(model);
|
||||
source.SaveDocuments();
|
||||
return document.GetViewModel;
|
||||
}
|
||||
public DocumentViewModel? Delete(DocumentBindingModel model)
|
||||
{
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (document == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
document.Update(model);
|
||||
source.SaveDocuments();
|
||||
return document.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
87
LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs
Normal file
87
LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
internal class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return order.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user