Реализован пользователь

This commit is contained in:
Николай 2023-04-01 17:34:07 +04:00
parent d8423e1e33
commit 92c765b663
2 changed files with 69 additions and 1 deletions

View File

@ -1,6 +1,11 @@
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using System.ComponentModel; using HardwareShopContracts.BindingModels;
using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.Storekeeper;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using HardwareShopDatabaseImplement.Models.Worker;
namespace HardwareShopDatabaseImplement.Models namespace HardwareShopDatabaseImplement.Models
{ {
@ -8,12 +13,71 @@ namespace HardwareShopDatabaseImplement.Models
{ {
public int Id { get; set; } public int Id { get; set; }
[Required]
public string Login { get; set; } = string.Empty; public string Login { get; set; } = string.Empty;
[Required]
public string Email { get; set; } = string.Empty; public string Email { get; set; } = string.Empty;
[Required]
public string Password { get; set; } = string.Empty; public string Password { get; set; } = string.Empty;
[Required]
public UserRole Role { get; set; } = UserRole.Неизвестен; public UserRole Role { get; set; } = UserRole.Неизвестен;
[ForeignKey("ClientId")]
public virtual List<Order> Orders { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Build> Builds { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Comment> Comments { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Purchase> Purchases { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Component> Components { get; set; } = new();
[ForeignKey("ClientId")]
public virtual List<Good> Goods { get; set; } = new();
public static User? Create(UserBindingModel? model)
{
if (model == null)
{
return null;
}
return new User()
{
Id = model.Id,
Login = model.Login,
Email = model.Email,
Password = model.Password,
Role = model.Role
};
}
public void Update(UserBindingModel? model)
{
if (model == null)
{
return;
}
Login = model.Login;
Password = model.Password;
Email = model.Email;
}
public UserViewModel GetViewModel => new()
{
Id = Id,
Login = Login,
Email = Email,
Password = Password,
Role = Role,
};
} }
} }

View File

@ -3,6 +3,7 @@ using HardwareShopContracts.ViewModels;
using HardwareShopDatabaseImplement.Models.ManyToMany; using HardwareShopDatabaseImplement.Models.ManyToMany;
using HardwareShopDataModels.Enums; using HardwareShopDataModels.Enums;
using HardwareShopDataModels.Models; using HardwareShopDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics; using System.Diagnostics;
@ -12,12 +13,15 @@ namespace HardwareShopDatabaseImplement.Models.Worker
{ {
public int Id { get; set; } public int Id { get; set; }
[Required]
public decimal Sum { get; set; } public decimal Sum { get; set; }
[Required]
public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен; public PurchaseStatus PurchaseStatus { get; set; } = PurchaseStatus.Неизвестен;
public DateTime? DatePurchase { get; set; } public DateTime? DatePurchase { get; set; }
[Required]
public int UserId { get; set; } public int UserId { get; set; }
public virtual User User { get; set; } public virtual User User { get; set; }