Добавление поля о клиенте в заказ во всех проектах
This commit is contained in:
parent
c517174585
commit
fc0d710479
@ -97,6 +97,13 @@ namespace FurnitureAssemFileImplement.Implements
|
||||
orderViewModel.FurnitureName = furniture.FurnitureName;
|
||||
}
|
||||
}
|
||||
foreach (var client in source.Clients)
|
||||
{
|
||||
if (client.Id == order.ClientId)
|
||||
{
|
||||
orderViewModel.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
}
|
||||
return orderViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -45,7 +47,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
|
||||
@ -61,7 +64,8 @@ namespace FurnitureAssemFileImplement.Models
|
||||
FurnitureId = Convert.ToInt32(element.Element("FurnitureId")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null),
|
||||
ClientId = Convert.ToInt32(element.Element("ClientId")!.Value)
|
||||
};
|
||||
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
|
||||
|
||||
@ -94,11 +98,13 @@ namespace FurnitureAssemFileImplement.Models
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("ClientId", ClientId),
|
||||
new XElement("FurnitureId", FurnitureId),
|
||||
new XElement("Count", Count.ToString()),
|
||||
new XElement("Sum", Sum.ToString()),
|
||||
|
@ -17,5 +17,6 @@ namespace FurnitureAssemblyContracts.BindingModels
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,9 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int ClientId { get; set; }
|
||||
[DisplayName("Клиент")]
|
||||
public string ClientFIO { get; set; } = string.Empty;
|
||||
public int FurnitureId { get; set; }
|
||||
[DisplayName("Изделие")]
|
||||
public string FurnitureName { get; set; } = string.Empty;
|
||||
@ -25,6 +28,6 @@ namespace FurnitureAssemblyContracts.ViewModels
|
||||
[DisplayName("Дата создания")]
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
[DisplayName("Дата выполнения")]
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public DateTime? DateImplement { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -15,5 +15,7 @@ namespace FurnitureAssemblyDataModels.Models
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
DateTime? DateImplement { get; }
|
||||
|
||||
int ClientId { get; }
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
return new();
|
||||
}
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Orders.Include(x => x.Furniture).FirstOrDefault(x =>
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x =>
|
||||
(model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
@ -36,6 +36,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.Id == model.Id || model.DateFrom <= x.DateCreate && x.DateCreate <= model.DateTo)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -46,6 +47,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
using var context = new FurnitureAssemblyDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Furniture)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -60,7 +62,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -73,7 +75,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
}
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
@ -84,7 +86,7 @@ namespace FurnitureAssemblyDatabaseImplement.Implements
|
||||
{
|
||||
context.Orders.Remove(order);
|
||||
context.SaveChanges();
|
||||
return context.Orders.Include(x => x.Furniture).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
return context.Orders.Include(x => x.Furniture).Include(x => x.Client).FirstOrDefault(x => x.Id == order.Id)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -29,6 +29,11 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public virtual Furniture Furniture { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
@ -45,7 +50,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
|
||||
@ -59,7 +65,8 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
|
||||
@ -82,7 +89,9 @@ namespace FurnitureAssemblyDatabaseImplement.Models
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId,
|
||||
ClientFIO = Client.ClientFIO
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -116,6 +116,13 @@ namespace FurnitureAssemblyListImplement.Implements
|
||||
orderViewModel.FurnitureName = furniture.FurnitureName;
|
||||
}
|
||||
}
|
||||
foreach (var client in _source.Clients)
|
||||
{
|
||||
if (client.Id == order.ClientId)
|
||||
{
|
||||
orderViewModel.ClientFIO = client.ClientFIO;
|
||||
}
|
||||
}
|
||||
return orderViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -24,10 +24,12 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ClientId { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -42,7 +44,8 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
DateImplement = model.DateImplement,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
|
||||
@ -65,7 +68,8 @@ namespace FurnitureAssemblyListImplement.Models
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
DateImplement = DateImplement,
|
||||
ClientId = ClientId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user