CourseWork_EventVisitor/EventVisitor/EventVisitorDatabase/Entities/EventEntity.cs

140 lines
4.5 KiB
C#
Raw Normal View History

2024-11-03 01:20:30 +04:00
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;
2024-11-03 10:18:08 +04:00
using System.ComponentModel.DataAnnotations;
2024-11-03 01:20:30 +04:00
namespace EventVisitorDatabase.Entities
{
public class EventEntity
{
public int Id { get; set; }
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string Name { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public DateTime Date { get; set; }
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public DateTime TimeStart { get; set; }
public DateTime TimeEnd { get; set; }
public string Description { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string Type { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string ContactPhone { get; set; } = string.Empty;
public string ContactEmail { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string Address { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string City { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public string Status { get; set; } = string.Empty;
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public int CountVisitors { get; set; }
2024-11-03 10:18:08 +04:00
[Required]
2024-11-03 01:20:30 +04:00
public int FreePlaces { get; set; }
[Required]
public int OrganizerId { get; set; }
2024-11-03 01:20:30 +04:00
public string Link { get; set; } = string.Empty;
public virtual OrganizerEntity Organizer { get; set; }
2024-11-03 01:20:30 +04:00
public static EventEntity? Create(EventBindingModel model)
{
if (model == null)
{
return null;
}
return new EventEntity()
{
Id = model.Id,
2024-11-03 01:20:30 +04:00
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
2024-11-03 01:20:30 +04:00
};
}
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
2024-11-03 01:20:30 +04:00
};
}
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
2024-11-03 01:20:30 +04:00
};
}
}