128 lines
3.5 KiB
C#
128 lines
3.5 KiB
C#
using PlumbingRepairContracts.BindingModels;
|
|
using PlumbingRepairContracts.SearchModels;
|
|
using PlumbingRepairContracts.StoragesContracts;
|
|
using PlumbingRepairContracts.ViewModels;
|
|
using PlumbingRepairDataModels.Models;
|
|
using PlumbingRepairListImplement.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PlumbingRepairListImplement.Implements
|
|
{
|
|
public class StoreStorage : IStoreStorage
|
|
{
|
|
private readonly DataListSingleton _source;
|
|
public StoreStorage()
|
|
{
|
|
_source = DataListSingleton.GetInstance();
|
|
}
|
|
public StoreViewModel? Delete(StoreBindingModel model)
|
|
{
|
|
for (int i = 0; i < _source.Stores.Count; ++i)
|
|
{
|
|
if (_source.Stores[i].Id == model.Id)
|
|
{
|
|
var element = _source.Stores[i];
|
|
_source.Stores.RemoveAt(i);
|
|
return element.GetViewModel;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public StoreViewModel? GetElement(StoreSearchModel model)
|
|
{
|
|
if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
foreach (var store in _source.Stores)
|
|
{
|
|
if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id))
|
|
{
|
|
return store.GetViewModel;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
|
|
{
|
|
var result = new List<StoreViewModel>();
|
|
|
|
if (string.IsNullOrEmpty(model.StoreName))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
foreach (var store in _source.Stores)
|
|
{
|
|
if (store.StoreName.Contains(model.StoreName))
|
|
{
|
|
result.Add(store.GetViewModel);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public List<StoreViewModel> GetFullList()
|
|
{
|
|
var result = new List<StoreViewModel>();
|
|
|
|
foreach (var store in _source.Stores)
|
|
{
|
|
result.Add(store.GetViewModel);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public StoreViewModel? Insert(StoreBindingModel model)
|
|
{
|
|
model.Id = 1;
|
|
|
|
foreach (var store in _source.Stores)
|
|
{
|
|
if (model.Id <= store.Id)
|
|
{
|
|
model.Id = store.Id + 1;
|
|
}
|
|
}
|
|
|
|
var newStore = Store.Create(model);
|
|
|
|
if (newStore == null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
_source.Stores.Add(newStore);
|
|
|
|
return newStore.GetViewModel;
|
|
}
|
|
public bool SellWork(IWorkModel model, int quantity)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
public StoreViewModel? Update(StoreBindingModel model)
|
|
{
|
|
foreach (var store in _source.Stores)
|
|
{
|
|
if (store.Id == model.Id)
|
|
{
|
|
store.Update(model);
|
|
return store.GetViewModel;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|