This commit is contained in:
Данила 2023-04-02 18:13:33 +04:00
parent 95f3d35609
commit 1004237bb7
5 changed files with 232 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FoodOrdersContracts\FoodOrdersContracts.csproj" />
<ProjectReference Include="..\FoodOrdersDataModel\FoodOrdersDataModel.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,64 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModel.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FoodOrderFileImplement.Models
{
internal class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static Component? Create(ComponentBindingModel? model)
{
if (model == null)
{
return null;
}
return new Component()
{
Id = model.Id,
ComponentName = model.ComponentName,
Cost = model.Cost
};
}
public static Component? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToInt32(element.Element("Cost")!.Value)
};
}
public void Update(ComponentBindingModel? model)
{
if (model == null)
{
return;
}
ComponentName = model.ComponentName;
Cost = model.Cost;
}
public ComponentViewModel GetViewModel => new()
{
Id = Id,
ComponentName = ComponentName,
Cost = Cost
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,72 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModel.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace FoodOrderFileImplement.Models
{
public class Food : IFoodModel
{
public int Id { get; private set; }
public string FoodName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
private Dictionary<int, (IComponentModel, int)> _foodComponents = null;
public Dictionary<int, (IComponentModel, int)> FoodComponents
{
get;
private set;
} = new Dictionary<int, (IComponentModel, int)>();
public static Food? Create(FoodBindingModel? model)
{
if (model == null)
{
return null;
}
return new Food()
{
Id = model.Id,
FoodName = model.FoodName,
Price = model.Price,
Components = model.FoodComponents.ToDictionary(x=>x.Key, x=>x.Value.Item2)
};
}
public static Food? Create(XElement element)
{
if(element == null)
{
return null;
}
return new Food()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
FoodName = element.Element("FoodName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("FoodComponents")!.Elements("FoodComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(FoodBindingModel? model)
{
if (model == null)
{
return;
}
FoodName = model.FoodName;
Price = model.Price;
FoodComponents = model.FoodComponents;
}
public FoodViewModel GetViewModel => new()
{
Id = Id,
FoodName = FoodName,
Price = Price,
FoodComponents = FoodComponents
};
}
}

View File

@ -0,0 +1,76 @@
using FoodOrdersContracts.BindingModels;
using FoodOrdersContracts.ViewModels;
using FoodOrdersDataModel.Enums;
using FoodOrdersDataModel.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 FoodOrderFileImplement.Models
{
internal class Order : IOrderModel
{
public int Id { get; private set; }
public int FoodId { get; private set; }
public string FoodName { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel? model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
FoodId = model.FoodId,
FoodName = model.FoodName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public static Order? Create(XElement element)
{
return new Order();
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
FoodId = model.FoodId;
FoodName = model.FoodName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
FoodId = FoodId,
FoodName = FoodName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order");
}
}

View File

@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrdersListImplement", "
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FoodOrderBusinessLogic", "FoodOrdersBusinessLogic\FoodOrderBusinessLogic.csproj", "{B3E18E56-A55D-47DC-8BFD-51689EE95375}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FoodOrderFileImplement", "FoodOrderFileImplement\FoodOrderFileImplement.csproj", "{0F8C8473-B376-4D36-88DA-478AFBE81BFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{B3E18E56-A55D-47DC-8BFD-51689EE95375}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3E18E56-A55D-47DC-8BFD-51689EE95375}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3E18E56-A55D-47DC-8BFD-51689EE95375}.Release|Any CPU.Build.0 = Release|Any CPU
{0F8C8473-B376-4D36-88DA-478AFBE81BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F8C8473-B376-4D36-88DA-478AFBE81BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F8C8473-B376-4D36-88DA-478AFBE81BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F8C8473-B376-4D36-88DA-478AFBE81BFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE