CourseWork_EventVisitor/EventVisitor/EventVisitorDatabase/Entities/SentMessageEntity.cs

69 lines
2.0 KiB
C#
Raw Normal View History

using DocumentFormat.OpenXml.Wordprocessing;
using EventVisitorLogic.BindingModels;
using EventVisitorLogic.ViewModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EventVisitorDatabase.Entities
{
public class SentMessageEntity
{
public int Id { get; set; }
[Required]
public int OrganizerId { get; set; }
[Required]
public int EventId { get; set; }
[Required]
public string Subject { get; set; } = string.Empty;
[Required]
public string Body { get; set; } = string.Empty;
[Required]
public DateTime SentDate { get; set; }
public virtual OrganizerEntity Organizer { get; set; }
public virtual EventEntity Event { get; set; }
public static SentMessageEntity? Create(SentMessageBindingModel model)
{
if (model == null)
{
return null;
}
return new SentMessageEntity()
{
Id = model.Id,
OrganizerId = model.OrganizerId,
EventId = model.EventId,
Subject = model.Subject,
Body = model.Body,
SentDate = model.SentDate
};
}
public static SentMessageEntity Create(SentMessageViewModel model)
{
return new SentMessageEntity()
{
Id = model.Id,
OrganizerId = model.OrganizerId,
EventId = model.EventId,
Subject = model.Subject,
Body = model.Body,
SentDate = model.SentDate
};
}
public SentMessageViewModel GetViewModel => new()
{
Id = Id,
OrganizerId = OrganizerId,
EventId = EventId,
Subject = Subject,
Body = Body,
SentDate = SentDate
};
}
}