pre final
This commit is contained in:
parent
3de75dc783
commit
accc28176f
@ -0,0 +1,91 @@
|
||||
using AbstractSoftwareInstallationContracts.BindingModels;
|
||||
using AbstractSoftwareInstallationContracts.SearchModels;
|
||||
using AbstractSoftwareInstallationContracts.StoragesContracts;
|
||||
using AbstractSoftwareInstallationContracts.ViewModels;
|
||||
using AbstractSoftwareInstallationFileImplement.Models;
|
||||
|
||||
namespace AbstractSoftwareInstallationFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetViewModel(source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).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 GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
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 GetViewModel(order);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var package = source.Packages.FirstOrDefault(x => x.Id == order.PackageId);
|
||||
if (package != null)
|
||||
{
|
||||
viewModel.PackageName = package.PackageName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
using AbstractSoftwareInstallationContracts.BindingModels;
|
||||
using AbstractSoftwareInstallationContracts.SearchModels;
|
||||
using AbstractSoftwareInstallationContracts.StoragesContracts;
|
||||
using AbstractSoftwareInstallationContracts.ViewModels;
|
||||
using AbstractSoftwareInstallationFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AbstractSoftwareInstallationFileImplement.Implements
|
||||
{
|
||||
public class PackageStorage : IPackageStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public PackageStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public PackageViewModel? GetElement(PackageSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Packages
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) && x.PackageName == model.PackageName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<PackageViewModel> GetFilteredList(PackageSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.PackageName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Packages
|
||||
.Where(x => x.PackageName.Contains(model.PackageName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<PackageViewModel> GetFullList()
|
||||
{
|
||||
return source.Packages.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public PackageViewModel? Insert(PackageBindingModel model)
|
||||
{
|
||||
model.Id = source.Packages.Count > 0 ? source.Packages.Max(x => x.Id) + 1 : 1;
|
||||
var newPackage = Package.Create(model);
|
||||
if (newPackage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Packages.Add(newPackage);
|
||||
source.SavePackages();
|
||||
return newPackage.GetViewModel;
|
||||
}
|
||||
|
||||
public PackageViewModel? Update(PackageBindingModel model)
|
||||
{
|
||||
var Package = source.Packages.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (Package == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Package.Update(model);
|
||||
source.SavePackages();
|
||||
return Package.GetViewModel;
|
||||
}
|
||||
public PackageViewModel? Delete(PackageBindingModel model)
|
||||
{
|
||||
var Package = source.Packages.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (Package == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Packages.Remove(Package);
|
||||
source.SavePackages();
|
||||
return Package.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using AbstractSoftwareInstallationContracts.BindingModels;
|
||||
using AbstractSoftwareInstallationContracts.SearchModels;
|
||||
using AbstractSoftwareInstallationContracts.StoragesContracts;
|
||||
using AbstractSoftwareInstallationContracts.ViewModels;
|
||||
using AbstractSoftwareInstallationFileImplement.Models;
|
||||
|
||||
namespace AbstractSoftwareInstallationFileImplement.Implements
|
||||
{
|
||||
public class SoftwareStorage : ISoftwareStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public SoftwareStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public List<SoftwareViewModel> GetFullList()
|
||||
{
|
||||
return _source.Softwares.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
public List<SoftwareViewModel> GetFilteredList(SoftwareSearchModel
|
||||
model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SoftwareName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return _source.Softwares.Where(x => x.SoftwareName.Contains(model.SoftwareName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
public SoftwareViewModel? GetElement(SoftwareSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.SoftwareName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _source.Softwares.FirstOrDefault(x => (!string.IsNullOrEmpty(model.SoftwareName) && x.SoftwareName == model.SoftwareName)
|
||||
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
public SoftwareViewModel? Insert(SoftwareBindingModel model)
|
||||
{
|
||||
model.Id = _source.Softwares.Count > 0 ? _source.Softwares.Max(x => x.Id) + 1 : 1;
|
||||
var newSoftware = Software.Create(model);
|
||||
if (newSoftware == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Softwares.Add(newSoftware);
|
||||
_source.SaveSoftwares();
|
||||
return newSoftware.GetViewModel;
|
||||
}
|
||||
public SoftwareViewModel? Update(SoftwareBindingModel model)
|
||||
{
|
||||
var software = _source.Softwares.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (software == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
software.Update(model);
|
||||
_source.SaveSoftwares();
|
||||
return software.GetViewModel;
|
||||
}
|
||||
public SoftwareViewModel? Delete(SoftwareBindingModel model)
|
||||
{
|
||||
var software = _source.Softwares.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (software == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Softwares.Remove(software);
|
||||
_source.SaveSoftwares();
|
||||
return software.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,8 @@
|
||||
using AbstractOrderInstallationListImplement.Implements;
|
||||
using AbstractPackageInstallationListImplement.Implements;
|
||||
using AbstractSoftwareInstallationFileImplement.Implements;
|
||||
using AbstractSoftwareInstallationBusinessLogic;
|
||||
using AbstractSoftwareInstallationBusinessLogic.BusinessLogic;
|
||||
using AbstractSoftwareInstallationContracts.BusinessLogicsContracts;
|
||||
using AbstractSoftwareInstallationContracts.StoragesContracts;
|
||||
using AbstractSoftwareInstallationListImplement.Implements;
|
||||
using SoftwareInstallationView;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AbstractSoftwareInstallationBusinessLogic\AbstractSoftwareInstallationBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\AbstractSoftwareInstallationContracts\AbstractSoftwareInstallationContracts.csproj" />
|
||||
<ProjectReference Include="..\AbstractSoftwareInstallationFileImplement\AbstractSoftwareInstallationFileImplement.csproj" />
|
||||
<ProjectReference Include="..\AbstractSoftwareInstallationListImplement\AbstractSoftwareInstallationListImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user