150 lines
5.0 KiB
C#
150 lines
5.0 KiB
C#
|
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;
|
|||
|
|
|||
|
namespace EventVisitorDatabase.Entities
|
|||
|
{
|
|||
|
public class EventEntity
|
|||
|
{
|
|||
|
public int Id { get; set; }
|
|||
|
public string Name { get; set; } = string.Empty;
|
|||
|
public DateTime Date { get; set; }
|
|||
|
public DateTime TimeStart { get; set; }
|
|||
|
public DateTime TimeEnd { get; set; }
|
|||
|
public string Description { get; set; } = string.Empty;
|
|||
|
public string Type { get; set; } = string.Empty;
|
|||
|
public string ContactPhone { get; set; } = string.Empty;
|
|||
|
public string ContactEmail { get; set; } = string.Empty;
|
|||
|
public string Address { get; set; } = string.Empty;
|
|||
|
public string City { get; set; } = string.Empty;
|
|||
|
public string Status { get; set; } = string.Empty;
|
|||
|
public int CountVisitors { get; set; }
|
|||
|
public int FreePlaces { get; set; }
|
|||
|
|
|||
|
[ForeignKey("EventId")]
|
|||
|
public virtual List<OrganizerEvent> Organizers { get; set; } = new();
|
|||
|
|
|||
|
private Dictionary<int, OrganizerEntity>? _eventOrginizers = null;
|
|||
|
[NotMapped]
|
|||
|
public Dictionary<int, OrganizerEntity> OrganizerEvent
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_eventOrginizers == null)
|
|||
|
{
|
|||
|
_eventOrginizers = Organizers
|
|||
|
.ToDictionary(rec => rec.OrganizerId, rec => (rec.Organizer as OrganizerEntity));
|
|||
|
}
|
|||
|
return _eventOrginizers;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static EventEntity? Create(EventBindingModel model)
|
|||
|
{
|
|||
|
if (model == null)
|
|||
|
{
|
|||
|
return null;
|
|||
|
}
|
|||
|
return new EventEntity()
|
|||
|
{
|
|||
|
Id = (int)(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
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
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
|
|||
|
};
|
|||
|
}
|
|||
|
|
|||
|
public void UpdateOrganizer(EventVisitorDbContext context, EventBindingModel model)
|
|||
|
{
|
|||
|
var events = context.Events.First(x => x.Id == Id);
|
|||
|
foreach (var fs in model.OrganizerEvent)
|
|||
|
{
|
|||
|
context.OrganizerEvent.Add(new OrganizerEvent
|
|||
|
{
|
|||
|
Event = events,
|
|||
|
Organizer = context.Organizers.First(x => x.Id == fs.Value.Id)
|
|||
|
});
|
|||
|
context.SaveChanges();
|
|||
|
}
|
|||
|
_eventOrginizers = null;
|
|||
|
}
|
|||
|
|
|||
|
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,
|
|||
|
};
|
|||
|
}
|
|||
|
}
|