71 lines
1.9 KiB
C#
71 lines
1.9 KiB
C#
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<Excursion> Excursions { get; set; } = new();
|
|
|
|
[ForeignKey("UserId")]
|
|
public virtual List<ExcursionGroup> ExcursionGroups { get; set; } = new();
|
|
|
|
[ForeignKey("UserId")]
|
|
public virtual List<Tour> 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
|
|
};
|
|
}
|
|
}
|