PIbd-21_Anisin_R.S._CourseW.../TravelAgency/TravelAgencyDatabaseImplement/Models/User.cs

71 lines
1.9 KiB
C#
Raw Normal View History

2024-04-28 23:08:12 +04:00
using System.ComponentModel.DataAnnotations;
2024-04-29 21:56:45 +04:00
using System.ComponentModel.DataAnnotations.Schema;
2024-04-28 23:08:12 +04:00
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;
2024-04-29 21:56:45 +04:00
[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();
2024-04-28 23:08:12 +04:00
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
};
}
}