FileImplements.

This commit is contained in:
Programmist73 2023-03-27 09:26:06 +04:00
parent a093ca253d
commit fadef43698
4 changed files with 60 additions and 28 deletions

View File

@ -15,7 +15,9 @@ namespace BlacksmithWorkshopContracts.ViewModels
[DisplayName("Номер")]
public int Id { get; set; }
public int ManufactureId { get; set; }
public int ClientId { get; set; }
public int ManufactureId { get; set; }
[DisplayName("Изделие")]
public string ManufactureName { get; set; } = string.Empty;
@ -34,5 +36,5 @@ namespace BlacksmithWorkshopContracts.ViewModels
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}
}
}

View File

@ -13,6 +13,9 @@ namespace BlacksmithWorkshopDataModels.Models
//id продукта
int ManufactureId { get; }
//id клиента
int ClientId { get; }
//кол-во продуктов
int Count { get; }

View File

@ -22,47 +22,69 @@ namespace BlacksmithWorkshopFileImplement.Implements
public List<ClientViewModel> GetFullList()
{
return source.Clients.Select(x => GetViewModel(x)).ToList();
return source.Clients.Select(x => x.GetViewModel).ToList();
}
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
{
throw new NotImplementedException();
}
return source.Clients.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
public ClientViewModel? GetElement(ClientSearchModel model)
{
throw new NotImplementedException();
}
//для загрузки названий изделия в заказе
private ClientViewModel GetViewModel(Client client)
{
var viewModel = order.GetViewModel;
var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == order.ManufactureId);
if (manufacture != null)
if (!model.Id.HasValue)
{
viewModel.ManufactureName = manufacture.ManufactureName;
return null;
}
return viewModel;
return source.Clients.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ClientViewModel? Insert(ClientBindingModel model)
{
throw new NotImplementedException();
}
model.Id = source.Clients.Count > 0 ? source.Clients.Max(x => x.Id) + 1 : 1;
var newClient = Client.Create(model);
if (newClient == null)
{
return null;
}
source.Clients.Add(newClient);
source.SaveClients();
return newClient.GetViewModel;
}
public ClientViewModel? Update(ClientBindingModel model)
{
throw new NotImplementedException();
}
var client = source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (client == null)
{
return null;
}
client.Update(model);
source.SaveClients();
return client.GetViewModel;
}
public ClientViewModel? Delete(ClientBindingModel model)
{
throw new NotImplementedException();
var element = source.Clients.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Clients.Remove(element);
source.SaveClients();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -17,7 +17,9 @@ namespace BlacksmithWorkshopFileImplement.Models
{
public int Id { get; private set; }
public int ManufactureId { get; private set; }
public int ClientId { get; private set; }
public int ManufactureId { get; private set; }
public int Count { get; private set; }
@ -39,6 +41,7 @@ namespace BlacksmithWorkshopFileImplement.Models
return new Order()
{
Id = model.Id,
ClientId = model.ClientId,
ManufactureId = model.ManufactureId,
Count = model.Count,
Sum = model.Sum,
@ -58,7 +61,8 @@ namespace BlacksmithWorkshopFileImplement.Models
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value),
ClientId = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
@ -82,6 +86,7 @@ namespace BlacksmithWorkshopFileImplement.Models
public OrderViewModel GetViewModel => new()
{
Id = Id,
ClientId = ClientId,
ManufactureId = ManufactureId,
Count = Count,
Sum = Sum,
@ -90,14 +95,14 @@ namespace BlacksmithWorkshopFileImplement.Models
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId.ToString()),
new XElement("ClientId", ClientId.ToString()),
new XElement("ManufactureId", ManufactureId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
}
}
}