role теперь enum + по мелочи
This commit is contained in:
parent
8388b39941
commit
752868c67f
@ -1,100 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityContracts.BindingModels;
|
|
||||||
using UniversityContracts.BusinessLogicContracts;
|
|
||||||
using UniversityContracts.SearchModels;
|
|
||||||
using UniversityContracts.StoragesContracts;
|
|
||||||
using UniversityContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace UniversityBusinessLogic.BusinessLogics
|
|
||||||
{
|
|
||||||
public class RoleLogic : IRoleLogic
|
|
||||||
{
|
|
||||||
private readonly IRoleStorage _roleStorage;
|
|
||||||
public RoleLogic(IRoleStorage roleStorage)
|
|
||||||
{
|
|
||||||
_roleStorage = roleStorage;
|
|
||||||
}
|
|
||||||
public bool Create(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_roleStorage.Insert(model) == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Delete(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
if (_roleStorage.Delete(model) == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleViewModel? ReadElement(RoleSearchModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
var element = _roleStorage.GetElement(model);
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RoleViewModel>? ReadList(RoleSearchModel? model)
|
|
||||||
{
|
|
||||||
var list = model == null ? _roleStorage.GetFullList() : _roleStorage.GetFilteredList(model);
|
|
||||||
if (list == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_roleStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckModel(RoleBindingModel model, bool withParams = true)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
if (!withParams)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Нет названия роли", nameof(model.Name));
|
|
||||||
}
|
|
||||||
|
|
||||||
var element = _roleStorage.GetElement(new RoleSearchModel
|
|
||||||
{
|
|
||||||
Name = model.Name
|
|
||||||
});
|
|
||||||
if (element != null && element.Id != model.Id)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Роль с таким названием уже есть");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityModels.Models;
|
|
||||||
|
|
||||||
namespace UniversityContracts.BindingModels
|
|
||||||
{
|
|
||||||
public class RoleBindingModel : IRoleModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
public string Name { get; set; } = string.Empty;
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityModels.Enums;
|
||||||
using UniversityModels.Models;
|
using UniversityModels.Models;
|
||||||
|
|
||||||
namespace UniversityContracts.BindingModels
|
namespace UniversityContracts.BindingModels
|
||||||
@ -11,7 +12,7 @@ namespace UniversityContracts.BindingModels
|
|||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public string Login { get; set; } = string.Empty;
|
public string Login { get; set; } = string.Empty;
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
public int RoleId { get; set; }
|
public Role Role { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityContracts.BindingModels;
|
|
||||||
using UniversityContracts.SearchModels;
|
|
||||||
using UniversityContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace UniversityContracts.BusinessLogicContracts
|
|
||||||
{
|
|
||||||
public interface IRoleLogic
|
|
||||||
{
|
|
||||||
List<RoleViewModel>? ReadList(RoleSearchModel? model);
|
|
||||||
RoleViewModel? ReadElement(RoleSearchModel model);
|
|
||||||
bool Create(RoleBindingModel model);
|
|
||||||
bool Update(RoleBindingModel model);
|
|
||||||
bool Delete(RoleBindingModel model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace UniversityContracts.SearchModels
|
|
||||||
{
|
|
||||||
public class RoleSearchModel
|
|
||||||
{
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public int? Id { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,8 +1,4 @@
|
|||||||
using System;
|
using UniversityModels.Enums;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace UniversityContracts.SearchModels
|
namespace UniversityContracts.SearchModels
|
||||||
{
|
{
|
||||||
@ -10,7 +6,7 @@ namespace UniversityContracts.SearchModels
|
|||||||
{
|
{
|
||||||
public int? Id { get; set; }
|
public int? Id { get; set; }
|
||||||
public string? Login { get; set; }
|
public string? Login { get; set; }
|
||||||
public DateTime? DateFrom { get; set; }
|
public string? Password { get; set; }
|
||||||
public DateTime? DateTo { get; set; }
|
public Role? Role { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityContracts.BindingModels;
|
|
||||||
using UniversityContracts.SearchModels;
|
|
||||||
using UniversityContracts.ViewModels;
|
|
||||||
|
|
||||||
namespace UniversityContracts.StoragesContracts
|
|
||||||
{
|
|
||||||
public interface IRoleStorage
|
|
||||||
{
|
|
||||||
List<RoleViewModel> GetFullList();
|
|
||||||
List<RoleViewModel> GetFilteredList(RoleSearchModel model);
|
|
||||||
RoleViewModel? GetElement(RoleSearchModel model);
|
|
||||||
RoleViewModel? Insert(RoleBindingModel model);
|
|
||||||
RoleViewModel? Update(RoleBindingModel model);
|
|
||||||
RoleViewModel? Delete(RoleBindingModel model);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityModels.Models;
|
|
||||||
|
|
||||||
namespace UniversityContracts.ViewModels
|
|
||||||
{
|
|
||||||
public class RoleViewModel : IRoleModel
|
|
||||||
{
|
|
||||||
[DisplayName("Название")]
|
|
||||||
public string Name { get; set; } = string.Empty;
|
|
||||||
|
|
||||||
public int Id { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,13 +4,15 @@ using System.ComponentModel;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityModels.Enums;
|
||||||
|
|
||||||
namespace UniversityContracts.ViewModels
|
namespace UniversityContracts.ViewModels
|
||||||
{
|
{
|
||||||
public class UserViewModel
|
public class UserViewModel
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
public int RoleId { get; set; }
|
[DisplayName("Роль")]
|
||||||
|
public Role Role { get; set; }
|
||||||
[DisplayName("Логин")]
|
[DisplayName("Логин")]
|
||||||
public string Login { get; set; } = string.Empty;
|
public string Login { get; set; } = string.Empty;
|
||||||
[DisplayName("Пароль")]
|
[DisplayName("Пароль")]
|
||||||
|
@ -10,7 +10,7 @@ namespace UniversityDataBaseImplemet
|
|||||||
{
|
{
|
||||||
if (optionsBuilder.IsConfigured == false)
|
if (optionsBuilder.IsConfigured == false)
|
||||||
{
|
{
|
||||||
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=University;Username=postgres;Password=123");
|
optionsBuilder.UseNpgsql("Host=localhost;Port=5432;Database=UniversityCourseWork;Username=postgres;Password=123");
|
||||||
}
|
}
|
||||||
base.OnConfiguring(optionsBuilder);
|
base.OnConfiguring(optionsBuilder);
|
||||||
}
|
}
|
||||||
@ -24,7 +24,6 @@ namespace UniversityDataBaseImplemet
|
|||||||
public virtual DbSet<Stream> Streams { get; set; }
|
public virtual DbSet<Stream> Streams { get; set; }
|
||||||
public virtual DbSet<Student> Students { get; set; }
|
public virtual DbSet<Student> Students { get; set; }
|
||||||
public virtual DbSet<StudentDocument> StudentDocuments { get; set; }
|
public virtual DbSet<StudentDocument> StudentDocuments { get; set; }
|
||||||
public virtual DbSet<StudentStream> StudentStreams { get; set; }
|
public virtual DbSet<StudentStream> StudentStreams { get; set; }
|
||||||
public virtual DbSet<Role> Roles { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,89 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityContracts.BindingModels;
|
|
||||||
using UniversityContracts.SearchModels;
|
|
||||||
using UniversityContracts.StoragesContracts;
|
|
||||||
using UniversityContracts.ViewModels;
|
|
||||||
using UniversityDataBaseImplemet.Models;
|
|
||||||
|
|
||||||
namespace UniversityDataBaseImplemet.Implements
|
|
||||||
{
|
|
||||||
public class RoleStorage : IRoleStorage
|
|
||||||
{
|
|
||||||
public RoleViewModel? Delete(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new Database();
|
|
||||||
var element = context.Roles
|
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Roles.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleViewModel? GetElement(RoleSearchModel model)
|
|
||||||
{
|
|
||||||
using var context = new Database();
|
|
||||||
if (model.Id.HasValue)
|
|
||||||
return context.Roles
|
|
||||||
.FirstOrDefault(record => record.Id == model.Id)
|
|
||||||
?.GetViewModel;
|
|
||||||
if (!string.IsNullOrEmpty(model.Name))
|
|
||||||
return context.Roles
|
|
||||||
.FirstOrDefault(record => record.Name.Equals(model.Name))
|
|
||||||
?.GetViewModel;
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RoleViewModel> GetFilteredList(RoleSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.Name))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new Database();
|
|
||||||
return context.Roles
|
|
||||||
.Where(record => record.Name.Contains(model.Name))
|
|
||||||
.Select(record => record.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<RoleViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new Database();
|
|
||||||
return context.Roles.Select(record => record.GetViewModel).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleViewModel? Insert(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
var newRole = Role.Create(model);
|
|
||||||
if (newRole == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new Database();
|
|
||||||
context.Roles.Add(newRole);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newRole.GetViewModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public RoleViewModel? Update(RoleBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new Database();
|
|
||||||
var client = context.Roles.FirstOrDefault(record => record.Id == model.Id);
|
|
||||||
if (client == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
client.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
return client.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -12,8 +12,8 @@ using UniversityDataBaseImplemet;
|
|||||||
namespace UniversityDataBaseImplemet.Migrations
|
namespace UniversityDataBaseImplemet.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(Database))]
|
[DbContext(typeof(Database))]
|
||||||
[Migration("20230515162605_lastStageStart")]
|
[Migration("20230516175336_fixRole")]
|
||||||
partial class lastStageStart
|
partial class fixRole
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
@ -176,23 +176,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.ToTable("EducationStatuses");
|
b.ToTable("EducationStatuses");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Role", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Roles");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -317,13 +300,11 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int>("RoleId")
|
b.Property<int>("Role")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("RoleId");
|
|
||||||
|
|
||||||
b.ToTable("User");
|
b.ToTable("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -485,17 +466,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.Navigation("Student");
|
b.Navigation("Student");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("UniversityDataBaseImplemet.Models.Role", "Role")
|
|
||||||
.WithMany("Users")
|
|
||||||
.HasForeignKey("RoleId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Role");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("EducationGroupDocument");
|
b.Navigation("EducationGroupDocument");
|
||||||
@ -515,11 +485,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.Navigation("Students");
|
b.Navigation("Students");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Role", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Users");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("EducationGroupStream");
|
b.Navigation("EducationGroupStream");
|
@ -7,24 +7,11 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace UniversityDataBaseImplemet.Migrations
|
namespace UniversityDataBaseImplemet.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public partial class lastStageStart : Migration
|
public partial class fixRole : Migration
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Roles",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
||||||
Name = table.Column<string>(type: "text", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Roles", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "User",
|
name: "User",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
@ -33,17 +20,11 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||||
Login = table.Column<string>(type: "text", nullable: false),
|
Login = table.Column<string>(type: "text", nullable: false),
|
||||||
Password = table.Column<string>(type: "text", nullable: false),
|
Password = table.Column<string>(type: "text", nullable: false),
|
||||||
RoleId = table.Column<int>(type: "integer", nullable: false)
|
Role = table.Column<int>(type: "integer", nullable: false)
|
||||||
},
|
},
|
||||||
constraints: table =>
|
constraints: table =>
|
||||||
{
|
{
|
||||||
table.PrimaryKey("PK_User", x => x.Id);
|
table.PrimaryKey("PK_User", x => x.Id);
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_User_Roles_RoleId",
|
|
||||||
column: x => x.RoleId,
|
|
||||||
principalTable: "Roles",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
@ -371,11 +352,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
name: "IX_StudentStreams_StudentId",
|
name: "IX_StudentStreams_StudentId",
|
||||||
table: "StudentStreams",
|
table: "StudentStreams",
|
||||||
column: "StudentId");
|
column: "StudentId");
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_User_RoleId",
|
|
||||||
table: "User",
|
|
||||||
column: "RoleId");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -413,9 +389,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
|
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "User");
|
name: "User");
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Roles");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -173,23 +173,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.ToTable("EducationStatuses");
|
b.ToTable("EducationStatuses");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Role", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("Name")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Roles");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -314,13 +297,11 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasColumnType("text");
|
.HasColumnType("text");
|
||||||
|
|
||||||
b.Property<int>("RoleId")
|
b.Property<int>("Role")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("RoleId");
|
|
||||||
|
|
||||||
b.ToTable("User");
|
b.ToTable("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -482,17 +463,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.Navigation("Student");
|
b.Navigation("Student");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.User", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("UniversityDataBaseImplemet.Models.Role", "Role")
|
|
||||||
.WithMany("Users")
|
|
||||||
.HasForeignKey("RoleId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Role");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Document", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("EducationGroupDocument");
|
b.Navigation("EducationGroupDocument");
|
||||||
@ -512,11 +482,6 @@ namespace UniversityDataBaseImplemet.Migrations
|
|||||||
b.Navigation("Students");
|
b.Navigation("Students");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Role", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Users");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
modelBuilder.Entity("UniversityDataBaseImplemet.Models.Stream", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("EducationGroupStream");
|
b.Navigation("EducationGroupStream");
|
||||||
|
@ -1,58 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using UniversityContracts.BindingModels;
|
|
||||||
using UniversityContracts.ViewModels;
|
|
||||||
using UniversityModels.Models;
|
|
||||||
|
|
||||||
namespace UniversityDataBaseImplemet.Models
|
|
||||||
{
|
|
||||||
public class Role : IRoleModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public string Name { get; set; } = string.Empty;
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
[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 static Role Create(RoleViewModel model)
|
|
||||||
{
|
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||||||
using UniversityContracts.BindingModels;
|
using UniversityContracts.BindingModels;
|
||||||
using UniversityContracts.ViewModels;
|
using UniversityContracts.ViewModels;
|
||||||
using UniversityModels.Models;
|
using UniversityModels.Models;
|
||||||
|
using UniversityModels.Enums;
|
||||||
|
|
||||||
namespace UniversityDataBaseImplemet.Models
|
namespace UniversityDataBaseImplemet.Models
|
||||||
{
|
{
|
||||||
@ -18,9 +19,8 @@ namespace UniversityDataBaseImplemet.Models
|
|||||||
public string Login { get; set; } = string.Empty;
|
public string Login { get; set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
[Required]
|
[Required]
|
||||||
public int RoleId { get; set; }
|
public Role Role { get; set; }
|
||||||
public virtual Role Role { get; set; } = new();
|
|
||||||
public static User Create(UserBindingModel model)
|
public static User Create(UserBindingModel model)
|
||||||
{
|
{
|
||||||
return new User()
|
return new User()
|
||||||
@ -28,20 +28,20 @@ namespace UniversityDataBaseImplemet.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
Login = model.Login,
|
Login = model.Login,
|
||||||
Password = model.Password,
|
Password = model.Password,
|
||||||
RoleId = model.RoleId
|
Role = model.Role
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
public void Update(UserBindingModel model)
|
public void Update(UserBindingModel model)
|
||||||
{
|
{
|
||||||
Password = model.Password;
|
Password = model.Password;
|
||||||
RoleId = model.RoleId;
|
Role = model.Role;
|
||||||
}
|
}
|
||||||
public UserViewModel GetViewModel => new()
|
public UserViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
Login = Login,
|
Login = Login,
|
||||||
Password = Password,
|
Password = Password,
|
||||||
RoleId = RoleId
|
Role = Role
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,11 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
|
||||||
<PackageReference Include="System.Diagnostics.Tools" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -4,10 +4,11 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace UniversityModels.Models
|
namespace UniversityModels.Enums
|
||||||
{
|
{
|
||||||
public interface IRoleModel : IId
|
public enum Role
|
||||||
{
|
{
|
||||||
string Name { get; }
|
Provider = 0,
|
||||||
}
|
Customer = 1
|
||||||
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using UniversityModels.Enums;
|
||||||
|
|
||||||
namespace UniversityModels.Models
|
namespace UniversityModels.Models
|
||||||
{
|
{
|
||||||
@ -10,7 +11,7 @@ namespace UniversityModels.Models
|
|||||||
{
|
{
|
||||||
string Login { get; }
|
string Login { get; }
|
||||||
string Password { get; }
|
string Password { get; }
|
||||||
int RoleId { get; }
|
Role Role { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
using System.IO.Pipes;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
@ -5,6 +7,8 @@ builder.Services.AddControllersWithViews();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -5,5 +5,6 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"IPAddress": "http://localhost:5067"
|
||||||
}
|
}
|
||||||
|
67
UniversityRestAPI/Controllers/UserController.cs
Normal file
67
UniversityRestAPI/Controllers/UserController.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using UniversityContracts.BindingModels;
|
||||||
|
using UniversityContracts.BusinessLogicContracts;
|
||||||
|
using UniversityContracts.SearchModels;
|
||||||
|
using UniversityContracts.ViewModels;
|
||||||
|
using UniversityDataBaseImplemet.Models;
|
||||||
|
using UniversityModels.Enums;
|
||||||
|
|
||||||
|
namespace UniversityRestAPI.Controllers
|
||||||
|
{
|
||||||
|
[Route("api/[controller]/[action]")]
|
||||||
|
[ApiController]
|
||||||
|
public class UserController : Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
private readonly IUserLogic _logic;
|
||||||
|
|
||||||
|
public UserController(IUserLogic logic, ILogger<UserController> logger)
|
||||||
|
{
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public UserViewModel? Login(string login, string password, Role role)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _logic.ReadElement(new UserSearchModel
|
||||||
|
{
|
||||||
|
Login = login,
|
||||||
|
Password = password,
|
||||||
|
Role = role
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(UserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Create(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost]
|
||||||
|
public void UpdateData(UserBindingModel model)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_logic.Update(model);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,6 @@ using UniversityDataBaseImplemet.Implements;
|
|||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddTransient<IUserStorage, UserStorage>();
|
builder.Services.AddTransient<IUserStorage, UserStorage>();
|
||||||
|
|
||||||
|
@ -7,11 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="Controllers\" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
Loading…
Reference in New Issue
Block a user