CourseWork_Hotel/Hotel/HotelDataBaseImplement/Models/Organiser.cs

82 lines
2.8 KiB
C#
Raw Normal View History

using HotelContracts.BindingModels;
using HotelContracts.ViewModels;
using HotelDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
2023-04-01 20:12:06 +04:00
namespace HotelDataBaseImplement.Models
{
public class Organiser : IOrganiserModel
{
[Required]
public string OrganiserFIO { get; set; } = string.Empty;
[Required]
public string OrganiserPassword { get; set; } = string.Empty;
[Required]
public string OrganiserLogin { get; set; } = string.Empty;
[Required]
public string OrganiserEmail { get; set; } = string.Empty;
[Required]
public string OrganiserNumber { get; set; } = string.Empty;
2023-04-01 20:12:06 +04:00
public int Id { get; private set; }
2023-04-01 20:12:06 +04:00
[ForeignKey("OrganiserId")]
public virtual List<Conference> Conferences { get; set; } = new();
[ForeignKey("OrganiserId")]
public virtual List<MealPlan> MealPlans { get; set; } = new();
[ForeignKey("OrganiserId")]
public virtual List<Member> Members { get; set; } = new();
2023-04-01 20:12:06 +04:00
public static Organiser? Create(OrganiserBindingModel model)
{
if (model == null)
{
return null;
}
return new Organiser()
{
Id = model.Id,
OrganiserFIO = model.OrganiserFIO,
OrganiserEmail = model.OrganiserEmail,
OrganiserPassword = model.OrganiserPassword,
OrganiserLogin = model.OrganiserLogin,
OrganiserNumber = model.OrganiserNumber
};
}
public static Organiser Create(OrganiserViewModel model)
{
return new Organiser
{
Id = model.Id,
OrganiserFIO = model.OrganiserFIO,
OrganiserEmail = model.OrganiserEmail,
OrganiserPassword = model.OrganiserPassword,
OrganiserLogin= model.OrganiserLogin,
OrganiserNumber= model.OrganiserNumber
};
}
public void Update(OrganiserBindingModel model)
{
if (model == null)
{
return;
}
OrganiserFIO = model.OrganiserFIO;
OrganiserEmail = model.OrganiserEmail;
OrganiserPassword = model.OrganiserPassword;
OrganiserLogin = model.OrganiserLogin;
OrganiserNumber = model.OrganiserNumber;
}
public OrganiserViewModel GetViewModel => new()
{
Id = Id,
OrganiserFIO = OrganiserFIO,
OrganiserEmail = OrganiserEmail,
OrganiserPassword = OrganiserPassword,
OrganiserNumber = OrganiserNumber,
OrganiserLogin = OrganiserLogin
};
2023-04-01 20:12:06 +04:00
}
}