Add implementer

This commit is contained in:
Viltskaa 2023-04-09 23:25:46 +04:00
parent 5d33fe2319
commit 003c54db7d
20 changed files with 572 additions and 4 deletions

View File

@ -0,0 +1,12 @@
using SushiBarDataModels.Models;
namespace SushiBarContracts.BindingModels;
public class ImplementerBindingModel : IImplementerModel
{
public int Id { get; set; }
public string ImplementerFio { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
public int WorkExperience { get; set; }
public int Qualification { get; set; }
}

View File

@ -8,6 +8,7 @@ namespace SushiBarContracts.BindingModels
public int Id { get; set; } public int Id { get; set; }
public int SushiId { get; set; } public int SushiId { get; set; }
public int ClientId { get; set; } public int ClientId { get; set; }
public int ImplementerId { get; set; }
public string ClientFio { get; set; } = string.Empty; public string ClientFio { get; set; } = string.Empty;
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
public int Count { get; set; } public int Count { get; set; }

View File

@ -0,0 +1,13 @@
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.BusinessLogicsContracts;
public interface IImplementerLogic
{
List<ImplementerViewModel>? ReadList(ImplementerSearchModel? model);
ImplementerViewModel? ReadElement(ImplementerSearchModel model);
bool Create(ImplementerSearchModel model);
bool Update(ImplementerSearchModel model);
bool Delete(ImplementerSearchModel model);
}

View File

@ -0,0 +1,10 @@
namespace SushiBarContracts.SearchModels;
public class ImplementerSearchModel
{
public int? Id { get; set; }
public string? ImplementerFio { get; set; }
public string? Password { get; set; }
public int? WorkExperience { get; set; }
public int? Qualification { get; set; }
}

View File

@ -6,5 +6,6 @@
public DateTime? DateFrom { get; set; } public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; } public DateTime? DateTo { get; set; }
public int? ClientId { get; set; } public int? ClientId { get; set; }
public int? ImplementerId { get; set; }
} }
} }

View File

@ -0,0 +1,15 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
namespace SushiBarContracts.StoragesContracts;
public interface IImplementerStorage
{
List<ImplementerViewModel> GetFullList();
List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model);
ImplementerViewModel? GetElement(ImplementerSearchModel? model);
ImplementerViewModel? Insert(ImplementerBindingModel model);
ImplementerViewModel? Update(ImplementerBindingModel model);
ImplementerViewModel? Delete(ImplementerBindingModel model);
}

View File

@ -0,0 +1,20 @@
using System.ComponentModel;
using SushiBarDataModels.Models;
namespace SushiBarContracts.ViewModels;
public class ImplementerViewModel : IImplementerModel
{
public int Id { get; init; }
[DisplayName("Implementer FIO")]
public string ImplementerFio { get; set; } = string.Empty;
public string Password { get; set; } = string.Empty;
[DisplayName("Work Experience")]
public int WorkExperience { get; set; }
[DisplayName("Qualification")]
public int Qualification { get; set; }
}

View File

@ -11,10 +11,14 @@ namespace SushiBarContracts.ViewModels
public int SushiId { get; init; } public int SushiId { get; init; }
public int ClientId { get; init; } public int ClientId { get; init; }
public int ImplementerId { get; set; }
[DisplayName("Client FIO")] [DisplayName("Client FIO")]
public string ClientFio { get; init; } = string.Empty; public string ClientFio { get; init; } = string.Empty;
[DisplayName("Implementer FIO")]
public string ImplementerFio { get; set; } = string.Empty;
[DisplayName("Name of Product")] [DisplayName("Name of Product")]
public string SushiName { get; init; } = string.Empty; public string SushiName { get; init; } = string.Empty;

View File

@ -0,0 +1,81 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Models;
namespace SushiBarDatabaseImplement.Implements;
public class ImplementerStorage : IImplementerStorage
{
public List<ImplementerViewModel> GetFullList()
{
using var context = new SushiBarDatabase();
return context.Implementers
.Select(x => x.GetViewModel)
.ToList();
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model)
{
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ? new List<ImplementerViewModel> { res } : new List<ImplementerViewModel>();
}
if (model.ImplementerFio == null) return new List<ImplementerViewModel>();
using var context = new SushiBarDatabase();
return context.Implementers
.Where(x => x.ImplementerFio.Equals(model.ImplementerFio))
.Select(x => x.GetViewModel)
.ToList();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel? model)
{
using var context = new SushiBarDatabase();
if (model.Id.HasValue)
return context.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model is { ImplementerFio: { }, Password: { } })
return context.Implementers
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio)
&& x.Password.Equals(model.Password))
?.GetViewModel;
return model.ImplementerFio != null ?
context.Implementers
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel :
null;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
using var context = new SushiBarDatabase();
var res = Implementer.Create(model);
if (res == null) return res?.GetViewModel;
context.Implementers.Add(res);
context.SaveChanges();
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
using var context = new SushiBarDatabase();
var res = context.Implementers
.FirstOrDefault(x => x.Id == model.Id);
if (res == null) return res?.GetViewModel;
res.Update(model);
context.SaveChanges();
return res?.GetViewModel;
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
using var context = new SushiBarDatabase();
var res = context.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res == null) return res?.GetViewModel;
context.Implementers.Remove(res);
context.SaveChanges();
return res?.GetViewModel;
}
}

View File

@ -0,0 +1,64 @@
using System.ComponentModel.DataAnnotations;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarDatabaseImplement.Models;
public class Implementer : IImplementerModel
{
public int Id { get; private init; }
[Required] public string ImplementerFio { get; private set; } = string.Empty;
[Required] public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(ImplementerBindingModel? model)
{
if (model == null)
return null;
return new Implementer
{
Id = model.Id,
ImplementerFio = model.ImplementerFio,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public static Implementer Create(ImplementerViewModel model)
{
return new Implementer()
{
Id = model.Id,
ImplementerFio = model.ImplementerFio,
Password = model.Password,
WorkExperience = model.WorkExperience,
Qualification = model.Qualification
};
}
public void Update(ImplementerBindingModel? model)
{
if (model == null)
{
return;
}
ImplementerFio = model.ImplementerFio;
Password = model.Password;
WorkExperience = model.WorkExperience;
Qualification = model.Qualification;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
ImplementerFio = ImplementerFio,
Password = Password,
WorkExperience = WorkExperience,
Qualification = Qualification
};
}

View File

@ -15,6 +15,7 @@ namespace SushiBarDatabaseImplement.Models
[Required] [Required]
public int ClientId { get; private set; } public int ClientId { get; private set; }
public int ImplementerId { get; private set; }
public string SushiName { get; set; } = string.Empty; public string SushiName { get; set; } = string.Empty;
@ -36,6 +37,8 @@ namespace SushiBarDatabaseImplement.Models
public virtual Client Client { get; set; } public virtual Client Client { get; set; }
public virtual Implementer? Implementer { get; private set; }
public static Order? Create(OrderBindingModel? model) public static Order? Create(OrderBindingModel? model)
{ {
if (model == null) if (model == null)
@ -49,6 +52,7 @@ namespace SushiBarDatabaseImplement.Models
SushiId = model.SushiId, SushiId = model.SushiId,
SushiName = model.SushiName, SushiName = model.SushiName,
ClientId = model.ClientId, ClientId = model.ClientId,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -67,6 +71,7 @@ namespace SushiBarDatabaseImplement.Models
SushiId = model.SushiId; SushiId = model.SushiId;
SushiName = model.SushiName; SushiName = model.SushiName;
ClientId = model.ClientId; ClientId = model.ClientId;
ImplementerId = model.ImplementerId;
Count = model.Count; Count = model.Count;
Sum = model.Sum; Sum = model.Sum;
Status = model.Status; Status = model.Status;
@ -85,10 +90,12 @@ namespace SushiBarDatabaseImplement.Models
Count = Count, Count = Count,
DateCreate = DateCreate, DateCreate = DateCreate,
DateImplement = DateImplement, DateImplement = DateImplement,
ImplementerId = ImplementerId,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty, ClientFio = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFio ?? string.Empty,
SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty SushiName = context.Sushi.FirstOrDefault(x => x.Id == SushiId)?.SushiName ?? string.Empty,
ImplementerFio = Implementer?.ImplementerFio ?? string.Empty
}; };
} } } }
} }

View File

@ -18,5 +18,6 @@ namespace SushiBarDatabaseImplement
public virtual DbSet<SushiComponent> SushiComponents { set; get; } public virtual DbSet<SushiComponent> SushiComponents { set; get; }
public virtual DbSet<Order> Orders { set; get; } public virtual DbSet<Order> Orders { set; get; }
public virtual DbSet<Client> Clients { set; get; } public virtual DbSet<Client> Clients { set; get; }
public virtual DbSet<Implementer> Implementers { get; set; }
} }
} }

View File

@ -9,9 +9,11 @@ namespace SushiBarFileImplement
private readonly string ComponentFileName = "Component.xml"; private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml"; private readonly string OrderFileName = "Order.xml";
private readonly string SushiFileName = "Sushi.xml"; private readonly string SushiFileName = "Sushi.xml";
private readonly string ImplementerFileName = "Implementer.xml";
public List<Component> Components { get; private set; } public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; } public List<Order> Orders { get; private set; }
public List<Sushi> Sushis { get; private set; } public List<Sushi> Sushis { get; private set; }
public List<Implementer> Implementers { get; set; }
public static DataFileSingleton GetInstance() public static DataFileSingleton GetInstance()
{ {
instance ??= new DataFileSingleton(); instance ??= new DataFileSingleton();
@ -20,11 +22,14 @@ namespace SushiBarFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement); public void SaveSushis() => SaveData(Sushis, SushiFileName, "Sushis", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveImplementers() => SaveData(Implementers, ImplementerFileName, "Implementers", x => x.GetXElement);
private DataFileSingleton() private DataFileSingleton()
{ {
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!; Sushis = LoadData(SushiFileName, "Sushi", x => Sushi.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
} }
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction) private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{ {

View File

@ -0,0 +1,89 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushiBarFileImplement.Models;
namespace SushiBarFileImplement.Implements;
public class ImplementerStorage : IImplementerStorage
{
private readonly DataFileSingleton _source;
public ImplementerStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<ImplementerViewModel> GetFullList()
{
return _source.Implementers.Select(x => x.GetViewModel).ToList();
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel? model)
{
if (model == null)
{
return new List<ImplementerViewModel>();
}
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ?
new List<ImplementerViewModel> { res } :
new List<ImplementerViewModel>();
}
if (model.ImplementerFio != null)
{
return _source.Implementers
.Where(x => x.ImplementerFio.Equals(model.ImplementerFio))
.Select(x => x.GetViewModel)
.ToList();
}
return new List<ImplementerViewModel>();
}
public ImplementerViewModel? GetElement(ImplementerSearchModel? model)
{
if (model.Id.HasValue)
return _source.Implementers.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
if (model is { ImplementerFio: { }, Password: { } })
return _source.Implementers
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio)
&& x.Password.Equals(model.Password))
?.GetViewModel;
return model.ImplementerFio != null ?
_source.Implementers
.FirstOrDefault(x => x.ImplementerFio.Equals(model.ImplementerFio))?.GetViewModel :
null;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = _source.Implementers.Count > 0 ?
_source.Implementers.Max(x => x.Id) + 1 :
1;
var res = Implementer.Create(model);
if (res == null) return res?.GetViewModel;
_source.Implementers.Add(res);
_source.SaveImplementers();
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res == null) return res?.GetViewModel;
res.Update(model);
_source.SaveImplementers();
return res?.GetViewModel;
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
var res = _source.Implementers.FirstOrDefault(x => x.Id == model.Id);
if (res == null) return res?.GetViewModel;
_source.Implementers.Remove(res);
_source.SaveImplementers();
return res?.GetViewModel;
}
}

View File

@ -0,0 +1,77 @@
using System.Xml.Linq;
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushiBarFileImplement.Models;
public class Implementer : IImplementerModel
{
public int Id { get; private set; }
public string ImplementerFio { get; private set; } = string.Empty;
public string Password { get; private set; } = string.Empty;
public int WorkExperience { get; private set; }
public int Qualification { get; private set; }
public static Implementer? Create(XElement? element)
{
if (element == null)
{
return null;
}
return new Implementer
{
ImplementerFio = element.Element("FIO")!.Value,
Password = element.Element("Password")!.Value,
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Qualification = Convert.ToInt32(element.Element("Qualification")!.Value),
WorkExperience = Convert.ToInt32(element.Element("WorkExperience")!.Value),
};
}
public static Implementer? Create(ImplementerBindingModel? model)
{
if (model == null)
{
return null;
}
return new Implementer
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFio = model.ImplementerFio,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel? model)
{
if (model == null)
{
return;
}
Password = model.Password;
Qualification = model.Qualification;
ImplementerFio = model.ImplementerFio;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFio = ImplementerFio,
};
public XElement GetXElement => new("Client",
new XAttribute("Id", Id),
new XElement("Password", Password),
new XElement("FIO", ImplementerFio),
new XElement("Qualification", Qualification),
new XElement("WorkExperience", WorkExperience)
);
}

View File

@ -12,6 +12,7 @@ namespace SushiBarFileImplement.Models
public string SushiName { get; private set; } = string.Empty; public string SushiName { get; private set; } = string.Empty;
public int SushiId { get; private set; } public int SushiId { get; private set; }
public int ClientId { get; } public int ClientId { get; }
public int ImplementerId { get; set; }
public int Count { get; private set; } public int Count { get; private set; }
public double Sum { get; private set; } public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Unknown; public OrderStatus Status { get; private set; } = OrderStatus.Unknown;
@ -29,6 +30,7 @@ namespace SushiBarFileImplement.Models
Id = model.Id, Id = model.Id,
SushiId = model.SushiId, SushiId = model.SushiId,
SushiName = model.SushiName, SushiName = model.SushiName,
ImplementerId = model.ImplementerId,
Count = model.Count, Count = model.Count,
Sum = model.Sum, Sum = model.Sum,
Status = model.Status, Status = model.Status,
@ -51,6 +53,7 @@ namespace SushiBarFileImplement.Models
Count = Convert.ToInt32(element.Element("Count")!.Value), Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value), Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value), Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
ImplementerId = Convert.ToInt32(element.Element("ImplementerId")!.Value),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null) DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
}; };
@ -67,6 +70,7 @@ namespace SushiBarFileImplement.Models
} }
SushiId = model.SushiId; SushiId = model.SushiId;
SushiName = model.SushiName; SushiName = model.SushiName;
ImplementerId = model.ImplementerId;
Count = model.Count; Count = model.Count;
Sum = model.Sum; Sum = model.Sum;
Status = model.Status; Status = model.Status;
@ -78,6 +82,9 @@ namespace SushiBarFileImplement.Models
Id = Id, Id = Id,
SushiId = SushiId, SushiId = SushiId,
SushiName = SushiName, SushiName = SushiName,
ImplementerFio = DataFileSingleton.GetInstance()
.Implementers
.FirstOrDefault(x => x.Id == ImplementerId)?.ImplementerFio ?? string.Empty,
Count = Count, Count = Count,
Sum = Sum, Sum = Sum,
Status = Status, Status = Status,
@ -89,6 +96,7 @@ namespace SushiBarFileImplement.Models
new XAttribute("Id", Id), new XAttribute("Id", Id),
new XElement("SushiName", SushiName), new XElement("SushiName", SushiName),
new XElement("SushiId", SushiId.ToString()), new XElement("SushiId", SushiId.ToString()),
new XElement("ImplementerId", ImplementerId),
new XElement("Count", Count.ToString()), new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()), new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()), new XElement("Status", Status.ToString()),

View File

@ -0,0 +1,9 @@
namespace SushiBarDataModels.Models;
public interface IImplementerModel : IId
{
string ImplementerFio { get; }
string Password { get; }
int WorkExperience { get; }
int Qualification { get; }
}

View File

@ -8,11 +8,14 @@ namespace SushibarListImplement
public List<Component> Components { get; set; } public List<Component> Components { get; set; }
public List<Order> Orders { get; set; } public List<Order> Orders { get; set; }
public List<Sushi> Sushi { get; set; } public List<Sushi> Sushi { get; set; }
public List<Implementer> Implementers { get; set; }
private DataListSingleton() private DataListSingleton()
{ {
Components = new List<Component>(); Components = new List<Component>();
Orders = new List<Order>(); Orders = new List<Order>();
Sushi = new List<Sushi>(); Sushi = new List<Sushi>();
Implementers = new List<Implementer>();
} }
public static DataListSingleton GetInstance() public static DataListSingleton GetInstance()
{ {

View File

@ -0,0 +1,106 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.StoragesContracts;
using SushiBarContracts.ViewModels;
using SushibarListImplement.Models;
namespace SushibarListImplement.Implements;
public class ImplementerStorage : IImplementerStorage
{
private readonly DataListSingleton _source;
public ImplementerStorage()
{
_source = DataListSingleton.GetInstance();
}
public ImplementerViewModel? Delete(ImplementerBindingModel model)
{
for (var i = 0; i < _source.Implementers.Count; ++i)
{
if (_source.Implementers[i].Id != model.Id) continue;
var element = _source.Implementers[i];
_source.Implementers.RemoveAt(i);
return element.GetViewModel;
}
return null;
}
public ImplementerViewModel? GetElement(ImplementerSearchModel model)
{
foreach (var x in _source.Implementers)
{
if (model.Id.HasValue && x.Id == model.Id)
return x.GetViewModel;
if (model.ImplementerFio != null && model.Password != null &&
x.ImplementerFio.Equals(model.ImplementerFio) && x.Password.Equals(model.Password))
return x.GetViewModel;
if (model.ImplementerFio != null && x.ImplementerFio.Equals(model.ImplementerFio))
return x.GetViewModel;
}
return null;
}
public List<ImplementerViewModel> GetFilteredList(ImplementerSearchModel model)
{
if (model.Id.HasValue)
{
var res = GetElement(model);
return res != null ?
new List<ImplementerViewModel> { res } :
new List<ImplementerViewModel>();
}
List<ImplementerViewModel> result = new();
if (model.ImplementerFio == null) return result;
foreach (var implementer in _source.Implementers)
{
if (implementer.ImplementerFio.Equals(model.ImplementerFio))
{
result.Add(implementer.GetViewModel);
}
}
return result;
}
public List<ImplementerViewModel> GetFullList()
{
var result = new List<ImplementerViewModel>();
foreach (var implementer in _source.Implementers)
{
result.Add(implementer.GetViewModel);
}
return result;
}
public ImplementerViewModel? Insert(ImplementerBindingModel model)
{
model.Id = 1;
foreach (var implementer in _source.Implementers)
{
if (model.Id <= implementer.Id)
{
model.Id = implementer.Id + 1;
}
}
var res = Implementer.Create(model);
if (res != null)
{
_source.Implementers.Add(res);
}
return res?.GetViewModel;
}
public ImplementerViewModel? Update(ImplementerBindingModel model)
{
foreach (var implementer in _source.Implementers)
{
if (implementer.Id == model.Id)
{
implementer.Update(model);
return implementer.GetViewModel;
}
}
return null;
}
}

View File

@ -0,0 +1,42 @@
using SushiBarContracts.BindingModels;
using SushiBarContracts.ViewModels;
using SushiBarDataModels.Models;
namespace SushibarListImplement.Models;
public class Implementer : IImplementerModel
{
public int Id { get; set; }
public string ImplementerFio { get; set; }
public string Password { get; set; }
public int WorkExperience { get; set; }
public int Qualification { get; set; }
public static Implementer? Create(ImplementerBindingModel model)
{
return new Implementer
{
Id = model.Id,
Password = model.Password,
Qualification = model.Qualification,
ImplementerFio = model.ImplementerFio,
WorkExperience = model.WorkExperience,
};
}
public void Update(ImplementerBindingModel model)
{
Password = model.Password;
Qualification = model.Qualification;
ImplementerFio = model.ImplementerFio;
WorkExperience = model.WorkExperience;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Password = Password,
Qualification = Qualification,
ImplementerFio = ImplementerFio,
};
}