CourseWorkElectronicsShop/ElectronicsShop/ElectronicsShopDataBaseImplement/Models/User.cs

91 lines
2.6 KiB
C#

using ElectronicsShopContracts.BindingModels;
using ElectronicsShopContracts.ViewModels;
using ElectronicsShopDataModels;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
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;
[Required]
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
};
}
}