using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using TravelAgencyContracts.BindingModels; using TravelAgencyContracts.ViewModels; using TravelAgencyDataModels.Models; namespace TravelAgencyDatabaseImplement.Models { public class User : IUserModel { public int Id { get; set; } [Required] public string UserFIO { get; set; } = string.Empty; [Required] public string Email { get; set; } = string.Empty; [Required] public string PhoneNumber { get; set; } = string.Empty; [Required] public string Password { get; set; } = string.Empty; [ForeignKey("UserId")] public virtual List Excursions { get; set; } = new(); [ForeignKey("UserId")] public virtual List ExcursionGroups { get; set; } = new(); [ForeignKey("UserId")] public virtual List Tours { get; set; } = new(); public static User? Create(UserBindingModel? model) { if (model == null) { return null; } return new User() { Id = model.Id, UserFIO = model.UserFIO, Email = model.Email, PhoneNumber = model.PhoneNumber, Password = model.Password, }; } public void Update(UserBindingModel? model) { if (model == null) { return; } UserFIO = model.UserFIO; Email = model.Email; PhoneNumber = model.PhoneNumber; Password = model.Password; } public UserViewModel GetViewModel => new() { Id = Id, UserFIO = UserFIO, Email = Email, PhoneNumber = PhoneNumber, Password = Password }; } }