using EventVisitorModels; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using System.Net.NetworkInformation; using System.Net; using System.Numerics; using System.Text; using System.Threading.Tasks; using static System.Runtime.InteropServices.JavaScript.JSType; using System.Xml.Linq; using EventVisitorLogic.ViewModels; using EventVisitorLogic.BindingModels; using System.ComponentModel.DataAnnotations; namespace EventVisitorDatabase.Entities { public class EventEntity { public int Id { get; set; } [Required] public string Name { get; set; } = string.Empty; [Required] public DateTime Date { get; set; } [Required] public DateTime TimeStart { get; set; } public DateTime TimeEnd { get; set; } public string Description { get; set; } = string.Empty; [Required] public string Type { get; set; } = string.Empty; [Required] public string ContactPhone { get; set; } = string.Empty; public string ContactEmail { get; set; } = string.Empty; [Required] public string Address { get; set; } = string.Empty; [Required] public string City { get; set; } = string.Empty; [Required] public string Status { get; set; } = string.Empty; [Required] public int CountVisitors { get; set; } [Required] public int FreePlaces { get; set; } [Required] public int OrganizerId { get; set; } public string Link { get; set; } = string.Empty; public static EventEntity? Create(EventBindingModel model) { if (model == null) { return null; } return new EventEntity() { Id = model.Id, Name = model.Name, Date = model.Date, TimeStart = model.TimeStart, TimeEnd = model.TimeEnd, Description = model.Description, Type = model.Type, ContactPhone = model.ContactPhone, ContactEmail = model.ContactEmail, Address = model.Address, City = model.City, Status = model.Status, CountVisitors = model.CountVisitors, FreePlaces = model.FreePlaces, OrganizerId = model.OrganizerId, Link = model.Link }; } public static EventEntity Create(EventViewModel model) { return new EventEntity() { Id = model.Id, Name = model.Name, Date = model.Date, TimeStart = model.TimeStart, TimeEnd = model.TimeEnd, Description = model.Description, Type = model.Type, ContactPhone = model.ContactPhone, ContactEmail = model.ContactEmail, Address = model.Address, City = model.City, Status = model.Status, CountVisitors = model.CountVisitors, FreePlaces = model.FreePlaces, OrganizerId = model.OrganizerId, Link = model.Link }; } public void Update(EventBindingModel model) { Name = model.Name; Date = model.Date; TimeStart = model.TimeStart; TimeEnd = model.TimeEnd; Description = model.Description; Type = model.Type; ContactPhone = model.ContactPhone; ContactEmail = model.ContactEmail; Address = model.Address; City = model.City; Status = model.Status; CountVisitors = model.CountVisitors; FreePlaces = model.FreePlaces; } public EventViewModel GetViewModel => new() { Id = Id, Name = Name, Date = Date, TimeStart = TimeStart, TimeEnd = TimeEnd, Description = Description, Type = Type, ContactPhone = ContactPhone, ContactEmail = ContactEmail, Address = Address, City = City, Status = Status, CountVisitors = CountVisitors, FreePlaces = FreePlaces, OrganizerId = OrganizerId, Link = Link }; } }