This commit is contained in:
Sergey Kozyrev 2024-04-24 12:35:17 +04:00
parent a4e790d380
commit 0c18013245
4 changed files with 70 additions and 10 deletions

View File

@ -19,6 +19,7 @@ namespace DatabaseImplement.Models
public virtual List<DetailProduct> DetailProducts { get; set; } = new();
[ForeignKey("DetailId")]
public virtual List<DetailProduction> DetailProductions { get; set; } = new();
public virtual Implementer User { get; set; }
public static Detail? Create(DetailBindingModel model)
{
if (model == null)

View File

@ -1,12 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Contracts.BindingModels;
using Contracts.ViewModels;
using DataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DatabaseImplement.Models
{
internal class Implementer
public class Implementer : IImplementerModel
{
public int Id { get; set; }
[Required]
public string Email { get; set; } = string.Empty;
[Required]
public string Name { get; set; } = string.Empty;
[Required]
public string Login { get; set; } = string.Empty;
[Required]
public string Password { get; set;} = string.Empty;
[ForeignKey("UserId")]
public virtual List<Detail> Details { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Product> Products { get; set; } = new();
[ForeignKey("UserId")]
public virtual List<Production> Productions { get; set; } = new();
public static Implementer? Create(ImplementerBindingModel model)
{
if (model == null)
{
return null;
}
return new Implementer
{
Id = model.Id,
Email = model.Email,
Name = model.Name,
Login = model.Login,
Password = model.Password
};
}
public static Implementer Create(ImplementerViewModel model)
{
return new Implementer
{
Id = model.Id,
Email = model.Email,
Name = model.Name,
Login = model.Login,
Password = model.Password
};
}
public void Update(ImplementerBindingModel model)
{
if (model == null)
return;
Email = model.Email;
Name = model.Name;
Password = model.Password;
}
public ImplementerViewModel GetViewModel => new()
{
Id = Id,
Email = Email,
Name = Name,
Login = Login,
Password = Password
};
}
}

View File

@ -15,6 +15,7 @@ namespace DatabaseImplement.Models
public double Cost { get; set; }
[Required]
public int UserId { get; set; }
public virtual Implementer User { get; set; }
private Dictionary<int, (IDetailModel, int)>? _detailProducts = null;
[NotMapped]
public Dictionary<int, (IDetailModel, int)> DetailProducts
@ -43,7 +44,7 @@ namespace DatabaseImplement.Models
Name = model.Name,
Cost = model.Cost,
UserId = model.UserId,
Details = model.DetailProducts.Select(x => new DetailProduct
Details = model.ProductDetails.Select(x => new DetailProduct
{
Detail = context.Details.First(y => y.Id == x.Key),
Count = x.Value.Item2

View File

@ -31,10 +31,9 @@ namespace DatabaseImplement.Models
}
}
[ForeignKey("ProductionId")]
public List<DetailProduction> Details { get; set; }
[ForeignKey("UserId")]
public List<DetailProduction> Details { get; set; } = new();
public virtual Implementer User { get; set; }
public static Production Create(FactoryGoWorkDatabase context, ProductionBindingModel model)
{
return new Production()