Реализация интерфейсов моделей.
This commit is contained in:
parent
3b4adf6001
commit
cdcdfa9709
@ -5,11 +5,13 @@ VisualStudioVersion = 17.4.33103.184
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshop", "BlacksmithWorkshop\BlacksmithWorkshop.csproj", "{FEF2DC94-D11E-4D77-9F59-5B89A09D0996}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopDataModels", "BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj", "{842406BF-3B58-4F5C-A4EB-AAB84F66ABEC}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts", "BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj", "{EBDA1A18-346F-4427-BC86-ED41C062A75B}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -33,6 +35,10 @@ Global
|
||||
{B3C97222-2894-4D74-B0D7-B3BEB347081D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B3C97222-2894-4D74-B0D7-B3BEB347081D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,63 @@
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
//класс реализующий интерфейс модели изделия
|
||||
public class Article : IArticleModel
|
||||
{
|
||||
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string ArticleName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public Dictionary<int, (IWorkPieceModel, int)> ArticleWorkPiece { get; private set; } = new Dictionary<int, (IWorkPieceModel, int)>();
|
||||
|
||||
//метод для создания объекта от класса-компонента на основе класса-BindingModel
|
||||
public static Article? Create(ArticleBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Article()
|
||||
{
|
||||
Id = model.Id,
|
||||
ArticleName = model.ArticleName,
|
||||
Price = model.Price,
|
||||
ArticleWorkPiece = model.ArticleWorkPiece
|
||||
};
|
||||
}
|
||||
|
||||
//метод изменения существующего объекта
|
||||
public void Update(ArticleBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ArticleName = model.ArticleName;
|
||||
Price = model.Price;
|
||||
ArticleWorkPiece = model.ArticleWorkPiece;
|
||||
}
|
||||
|
||||
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
|
||||
public ArticleViewModel GetViewModel() => new()
|
||||
{
|
||||
Id = Id,
|
||||
ArticleName = ArticleName,
|
||||
Price = Price,
|
||||
ArticleWorkPiece = ArticleWorkPiece
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDataModels.Enums;
|
||||
using BlacksmithWorkshopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.PortableExecutable;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
//класс, реализующий интерфейс модели заказа
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
//методы set сделали приватными, чтобы исключить неразрешённые манипуляции
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ArticleId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; }
|
||||
|
||||
public DateTime DateCreate { get; private set; }
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order()
|
||||
{
|
||||
ArticleId = model.ArticleId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate, //а надо ли?
|
||||
DateImplement = model.DateImplement //а надо ли?
|
||||
};
|
||||
}
|
||||
|
||||
//метод изменения существующего объекта
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ArticleId = model.ArticleId;
|
||||
Count = model.Count;
|
||||
Sum = model.Sum;
|
||||
Status = model.Status;
|
||||
DateCreate = model.DateCreate; //а надо ли?
|
||||
DateImplement = model.DateImplement; //а надо ли?
|
||||
}
|
||||
|
||||
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
|
||||
public OrderViewModel GetViewModel() => new()
|
||||
{
|
||||
ArticleId = ArticleId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate, //а надо ли?
|
||||
DateImplement = DateImplement //а надо ли?
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using BlacksmithWorkshopContracts.BindingModels;
|
||||
using BlacksmithWorkshopContracts.ViewModels;
|
||||
using BlacksmithWorkshopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlacksmithWorkshopListImplement.Models
|
||||
{
|
||||
//реализация интерфейса модели заготовки
|
||||
public class WorkPiece : IWorkPieceModel
|
||||
{
|
||||
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string WorkPieceName { get; private set; } = string.Empty;
|
||||
|
||||
public double Cost { get; private set; }
|
||||
|
||||
//метод для создания объекта от класса-компонента на основе класса-BindingModel
|
||||
public static WorkPiece? Create(WorkPieceBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new WorkPiece()
|
||||
{
|
||||
Id = model.Id,
|
||||
WorkPieceName = model.WorkPieceName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
//метод изменения существующего объекта
|
||||
public void Update(WorkPieceBindingModel? model)
|
||||
{
|
||||
if(model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
WorkPieceName = model.WorkPieceName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
//метод для создания объекта класса ViewModel на основе данных объекта класса-компонента
|
||||
public WorkPieceViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WorkPieceName = WorkPieceName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user