Превратил роль в enum

This commit is contained in:
maxnes3 2023-05-18 01:15:02 +04:00
parent 451bba118a
commit 3458d836cd
16 changed files with 26 additions and 123 deletions

View File

@ -1,16 +0,0 @@
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.BindingModels
{
public class RoleBindingModel : IRoleModel
{
public string Name { get; set; } = string.Empty;
public int Id { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using CaseAccountingDataModels.Models;
using CaseAccountingDataModels.Enum;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -13,7 +14,7 @@ namespace CaseAccountingContracts.BindingModels
public string Password { get; set; } = string.Empty;
public int RoleId { get; set; }
public Role Role { get; set; }
public int Id { get; set; }
}

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.SearchModels
{
public class RoleSearchModel
{
public int? Id { get; set; }
public string? Name { get; set; }
}
}

View File

@ -1,4 +1,5 @@
using System;
using CaseAccountingDataModels.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -14,6 +15,6 @@ namespace CaseAccountingContracts.SearchModels
public string? Password { get; set; }
public int? RoleId { get; set; }
public Role? Role { get; set; }
}
}

View File

@ -1,18 +0,0 @@
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingContracts.ViewModels
{
public class RoleViewModel : IRoleModel
{
public int Id { get; set; }
[DisplayName("Название роли")]
public string Name { get; set; } = string.Empty;
}
}

View File

@ -1,4 +1,5 @@
using CaseAccountingDataModels.Models;
using CaseAccountingDataModels.Enum;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
@ -16,6 +17,6 @@ namespace CaseAccountingContracts.ViewModels
public string Password { get; set; } = string.Empty;
public int RoleId { get; set; }
public Role Role { get; set; }
}
}

View File

@ -28,8 +28,6 @@ namespace CaseAccountingDataBaseImplement
public virtual DbSet<User> Users { set; get; }
public virtual DbSet<Role> Roles { set; get; }
public virtual DbSet<Contract> Contracts { set; get; }
public virtual DbSet<Deal> Deals { set; get; }

View File

@ -1,53 +0,0 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace CaseAccountingDataBaseImplement.Models
{
public class Role : IRoleModel
{
public int Id { get; set; }
[Required]
public string Name { get; set; } = string.Empty;
[ForeignKey("RoleId")]
public virtual List<User> Users { get; set; } = new();
public static Role? Create(RoleBindingModel? model)
{
if (model == null)
{
return null;
}
return new Role()
{
Id = model.Id,
Name = model.Name,
};
}
public void Update(RoleBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
}
public RoleViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
};
}
}

View File

@ -1,5 +1,6 @@
using CaseAccountingContracts.BindingModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataModels.Enum;
using CaseAccountingDataModels.Models;
using System;
using System.Collections.Generic;
@ -22,8 +23,7 @@ namespace CaseAccountingDataBaseImplement.Models
public string Password { get; set; } = string.Empty;
[Required]
public int RoleId { get; set; }
public virtual Role Role { get; set; } = new();
public Role Role { get; set; }
[ForeignKey("UserId")]
public virtual List<Hearing> Hearings { get; set; } = new();
@ -54,7 +54,7 @@ namespace CaseAccountingDataBaseImplement.Models
Id = model.Id,
Login = model.Login,
Password = model.Password,
RoleId = model.RoleId
Role = model.Role
};
}
@ -72,7 +72,7 @@ namespace CaseAccountingDataBaseImplement.Models
Id = Id,
Login = Login,
Password = Password,
RoleId = RoleId,
Role = Role,
};
}
}

View File

@ -4,10 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CaseAccountingDataModels.Models
namespace CaseAccountingDataModels.Enum
{
public interface IRoleModel : IId
public enum Role
{
string Name { get; }
Provider = 0,
Customer = 1
}
}

View File

@ -1,4 +1,5 @@
using System;
using CaseAccountingDataModels.Enum;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -10,6 +11,6 @@ namespace CaseAccountingDataModels.Models
{
string Login { get; }
string Password { get; }
int RoleId { get; }
Role Role { get; }
}
}

View File

@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers
{
try
{
return _logic.ReadList(null);
return _logic.ReadList(new CaseSearchModel { UserId = userId });
}
catch (Exception)
{

View File

@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers
{
try
{
return _logic.ReadList(null);
return _logic.ReadList(new ContractSearchModel { UserId = userId });
}
catch (Exception)
{

View File

@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers
{
try
{
return _logic.ReadList(null);
return _logic.ReadList(new DealSearchModel { UserId = userId });
}
catch (Exception)
{

View File

@ -35,7 +35,7 @@ namespace CaseAccountingRestApi.Controllers
{
try
{
return _logic.ReadList(null);
return _logic.ReadList(new HearingSearchModel { UserId = userId });
}
catch (Exception)
{

View File

@ -3,6 +3,7 @@ using CaseAccountingContracts.BusinessLogicContracts;
using CaseAccountingContracts.SearchModels;
using CaseAccountingContracts.ViewModels;
using CaseAccountingDataBaseImplement.Models;
using CaseAccountingDataModels.Enum;
using Microsoft.AspNetCore.Mvc;
namespace CaseAccountingRestApi.Controllers
@ -27,7 +28,7 @@ namespace CaseAccountingRestApi.Controllers
{
Login = login,
Password = password,
//Role = role
Role = role
});
}
catch (Exception)