PHP
- 1 ответ
- 0 вопросов
3
Вклад в тег
public abstract class Post
{
protected Post(string text, int writerId)
{
Text = text;
CreationDate = DateTime.Now;
WriterId = writerId;
}
public int Id { get; set; }
public string Text { get; private set; }
public DateTime CreationDate { get; private set; }
//Идентификатор писателя статьи\новости
public int WriterId { get; private set; }
//Автоматически подтягиваемая из базы модель писателя через ORM по WriterId
public virtual Writer Writer { get; set; }
}
public class Article : Post
{
public Picture[] Pictures { get; private set; }
public Article(string text, int writerId, Picture[] pictures) : base(text, writerId)
{
Pictures = pictures;
}
}
public class News : Post
{
public Picture Picture { get; }
//Массив комментариев к посту
// private set -- говорит о том что массив инкапсулирован
// и управлять массивом можно только через метод AddComment
public List<Commentary> Commentaries { get; private set; }
public News(string text, int writerId, Picture picture) : base(text, writerId)
{
Picture = picture;
}
public void AddComment(Commentary commentary)
{
Commentaries.Add(commentary);
}
}
public abstract class User
{
public int Id { get; set; }
public string Username { get; private set; }
public string Role { get; private set; }
protected User(string role, string username)
{
Role = role;
Username = username;
}
}
public class Subscriber : User
{
public string Email { get; private set; }
public Subscriber(string username, string email) : base(nameof(Subscriber), username)
{
Email = email;
}
}
public class Writer : User
{
public Writer(string username) : base(nameof(Writer), username)
{
}
}
public class Commentary
{
public int Id { get; set; }
public string CommentText { get; private set; }
public int UserId { get; private set; }
public virtual User User { get; private set; }
public DateTime CommentCreationDate { get; private set; }
public Commentary(int userId, string commentText)
{
UserId = userId;
CommentText = commentText;
CommentCreationDate = DateTime.Now;
}
}
if (DataBase.IsInMemory())
var autoGenIntProperties = modelBuilder.Model.GetEntityTypes()
.SelectMany(t => t.GetProperties())
.Where(p => p.ClrType == typeof(int) && p.ValueGenerated != ValueGenerated.Never);
foreach (var property in autoGenIntProperties)
property.SetValueGeneratorFactory((p, t) => new InMemoryIntegerValueGenerator<int>(p.GetIndex()));