productchange

This commit is contained in:
Sergey Kozyrev 2024-04-27 21:46:39 +04:00
parent e708ad671d
commit a87ad2e062
5 changed files with 16 additions and 3 deletions

View File

@ -8,6 +8,9 @@ namespace Contracts.BindingModels
public int UserId { get; set; }
public string Name { get; set; } = string.Empty;
public double Cost { get; set; }
public Dictionary<int, (IDetailModel, int)> ProductDetails { get; set; } = new();
}
public int? MachineId { get; set; }
}
}

View File

@ -11,5 +11,6 @@ namespace Contracts.SearchModels
public int? Id { get; set; }
public string? Name { get; set; }
public int? UserId { get; set; }
public int? MachineId { get; set; }
}
}

View File

@ -16,6 +16,7 @@ namespace Contracts.ViewModels
[DisplayName("Цена изделия")]
public double Cost { get; set; }
public int UserId { get; set; }
public int? MachineId { get; set; }
public Dictionary<int, (IDetailModel, int)> DetailProducts { get; set; } = new();
}
}

View File

@ -4,5 +4,6 @@
{
string Name { get; }
double Cost { get; }
int? MachineId { get; }
}
}

View File

@ -16,6 +16,8 @@ namespace DatabaseImplement.Models
[Required]
public int UserId { get; set; }
public virtual Implementer User { get; set; }
public int? MachineId { get; set; }
public virtual Machine? Machine { get; set; }
private Dictionary<int, (IDetailModel, int)>? _detailProducts = null;
[NotMapped]
public Dictionary<int, (IDetailModel, int)> DetailProducts
@ -44,6 +46,8 @@ namespace DatabaseImplement.Models
Name = model.Name,
Cost = model.Cost,
UserId = model.UserId,
MachineId = model.MachineId,
Machine = model.MachineId.HasValue ? context.Machines.FirstOrDefault(x => x.Id == model.MachineId) : null,
Details = model.ProductDetails.Select(x => new DetailProduct
{
Detail = context.Details.First(y => y.Id == x.Key),
@ -58,7 +62,8 @@ namespace DatabaseImplement.Models
Id = model.Id,
Name = model.Name,
Cost = model.Cost,
UserId = model.UserId
UserId = model.UserId,
MachineId = model.MachineId
};
}
public void Update(ProductBindingModel model)
@ -67,6 +72,7 @@ namespace DatabaseImplement.Models
return;
Name = model.Name;
Cost = model.Cost;
MachineId = model.MachineId;
}
public ProductViewModel GetViewModel => new()
{
@ -74,7 +80,8 @@ namespace DatabaseImplement.Models
Name = Name,
Cost = Cost,
UserId = UserId,
DetailProducts = DetailProducts
DetailProducts = DetailProducts,
MachineId= MachineId
};
public void UpdateDetails(FactoryGoWorkDatabase context, ProductBindingModel model)
{