Готова сущность Comment
This commit is contained in:
parent
33562b0143
commit
a7cebe62b7
@ -10,8 +10,6 @@ namespace HardwareShopContracts.BindingModels
|
||||
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
public int BuildID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,8 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
|
||||
public virtual User User { get; set; }
|
||||
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<Comment>? Comments { get; set; }
|
||||
|
||||
[ForeignKey("BuildId")]
|
||||
public virtual List<BuildComponent>? Components { get; set; }
|
||||
|
@ -1,5 +1,8 @@
|
||||
using HardwareShopDataModels.Models;
|
||||
using HardwareShopContracts.BindingModels;
|
||||
using HardwareShopContracts.ViewModels;
|
||||
using HardwareShopDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace HardwareShopDatabaseImplement.Models
|
||||
{
|
||||
@ -7,12 +10,41 @@ namespace HardwareShopDatabaseImplement.Models
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string Text { get; set; } = string.Empty;
|
||||
|
||||
public string BuildName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int BuildID { get; set; }
|
||||
|
||||
public virtual Build Build { get; set; }
|
||||
|
||||
public static Comment? Create(CommentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Comment()
|
||||
{
|
||||
Id = model.Id,
|
||||
Text = model.Text,
|
||||
BuildID = model.BuildID
|
||||
};
|
||||
}
|
||||
public void Update(CommentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Text = model.Text;
|
||||
}
|
||||
public CommentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Text = Text,
|
||||
BuildID = BuildID,
|
||||
BuildName = Build.BuildName
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user