Remade database, clients can now create purchases and components
This commit is contained in:
@@ -18,6 +18,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
public int ClientId { get; private set; }
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<AssemblyComponent> AssemblyComponents { get; set; } =
|
||||
new();
|
||||
@@ -35,7 +36,8 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
Cost = model.Cost,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
@@ -44,7 +46,8 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
Cost = model.Cost,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
@@ -55,12 +58,14 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
ClientId = model.ClientId;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
Cost = Cost,
|
||||
ClientId = ClientId
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
[Required]
|
||||
public int ComponentId { get; private set; }
|
||||
[Required]
|
||||
public int ClientId { get; private set; }
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
@@ -29,6 +31,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
public virtual Component Component { get; set; }
|
||||
public virtual Client Client { get; set; }
|
||||
|
||||
public static Purchase? Create(PurchaseBindingModel? model)
|
||||
{
|
||||
@@ -46,6 +49,7 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
ClientId = model.ClientId
|
||||
};
|
||||
}
|
||||
|
||||
@@ -59,16 +63,25 @@ namespace ComputerShopDatabaseImplement.Models
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public PurchaseViewModel GetViewModel => new()
|
||||
public PurchaseViewModel GetViewModel
|
||||
{
|
||||
ComponentId = ComponentId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
ComponentName = ComponentName
|
||||
};
|
||||
get
|
||||
{
|
||||
var context = new ComputerShopDatabase();
|
||||
return new()
|
||||
{
|
||||
ComponentId = ComponentId,
|
||||
ClientId = ClientId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
ComponentName = context.Components.FirstOrDefault(x => x.Id == ComponentId)?.ComponentName ?? string.Empty,
|
||||
ClientFIO = context.Clients.FirstOrDefault(x => x.Id == ClientId)?.ClientFIO ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user