59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using BlogContracts.BindingModel;
|
|
using BlogContracts.ViewModels;
|
|
using BlogDataModels.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace BlogDatabaseImplement.Model
|
|
{
|
|
public class User : IUser
|
|
{
|
|
[Required]
|
|
public string Name { get; set; } = string.Empty;
|
|
|
|
public string DateCreate { get; set; } = string.Empty;
|
|
[Required]
|
|
public int Id { get; set; }
|
|
|
|
[ForeignKey("UserId")]
|
|
List<News> News { get; set; } = new();
|
|
|
|
public static User? Create(UserBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return null;
|
|
}
|
|
return new User()
|
|
{
|
|
Id = model.Id,
|
|
Name = model.Name,
|
|
DateCreate = model.DateCreate
|
|
};
|
|
}
|
|
|
|
public void Update(UserBindingModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
return;
|
|
}
|
|
Name = model.Name;
|
|
DateCreate = model.DateCreate;
|
|
}
|
|
|
|
public UserViewModel GetViewModel => new()
|
|
{
|
|
Id = Id,
|
|
Name = Name,
|
|
DateCreate = DateCreate
|
|
};
|
|
}
|
|
}
|