2024-04-29 01:55:20 +04:00
|
|
|
|
using ElectronicsShopContracts.BindingModels;
|
|
|
|
|
using ElectronicsShopContracts.ViewModels;
|
|
|
|
|
using ElectronicsShopDataModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2024-04-30 21:59:22 +04:00
|
|
|
|
using System.ComponentModel.DataAnnotations.Schema;
|
2024-04-29 01:55:20 +04:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace ElectronicsShopDataBaseImplement.Models
|
|
|
|
|
{
|
|
|
|
|
public class User : IUserModel
|
|
|
|
|
{
|
|
|
|
|
public int ID { get; set; }
|
|
|
|
|
[Required]
|
|
|
|
|
public string FirstName { get; set; }=string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string LastName {get; set; }=string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Password { get; set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string PhoneNumber { get; set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Login { get; set; } = string.Empty;
|
|
|
|
|
[Required]
|
|
|
|
|
public string Email { get; set; } = string.Empty;
|
2024-04-30 21:59:22 +04:00
|
|
|
|
[ForeignKey("RoleID")]
|
2024-04-29 01:55:20 +04:00
|
|
|
|
public int RoleID { get; set; }
|
|
|
|
|
|
|
|
|
|
public static User? Create(UserBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if(model == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return new User()
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
|
|
|
|
FirstName = model.FirstName,
|
|
|
|
|
LastName = model.LastName,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
PhoneNumber = model.PhoneNumber,
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
RoleID = model.RoleID
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
public static User Create(UserViewModel model)
|
|
|
|
|
{
|
|
|
|
|
return new User
|
|
|
|
|
{
|
|
|
|
|
ID = model.ID,
|
|
|
|
|
FirstName = model.FirstName,
|
|
|
|
|
LastName = model.LastName,
|
|
|
|
|
Password = model.Password,
|
|
|
|
|
PhoneNumber = model.PhoneNumber,
|
|
|
|
|
Login = model.Login,
|
|
|
|
|
Email = model.Email,
|
|
|
|
|
RoleID = model.RoleID
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Update(UserBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
FirstName = model.FirstName;
|
|
|
|
|
LastName = model.LastName;
|
|
|
|
|
Password = model.Password;
|
|
|
|
|
PhoneNumber = model.PhoneNumber;
|
|
|
|
|
Login = model.Login;
|
|
|
|
|
Email = model.Email;
|
|
|
|
|
RoleID = model.RoleID;
|
|
|
|
|
}
|
|
|
|
|
public UserViewModel GetViewModel => new()
|
|
|
|
|
{
|
|
|
|
|
ID = ID,
|
|
|
|
|
FirstName = FirstName,
|
|
|
|
|
LastName = LastName,
|
|
|
|
|
Password = Password,
|
|
|
|
|
PhoneNumber = PhoneNumber,
|
|
|
|
|
Login = Login,
|
|
|
|
|
Email = Email,
|
|
|
|
|
RoleID = RoleID
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|