Role lista hozzáadása

This commit is contained in:
2025-03-18 12:12:12 +01:00
parent 5097757cfb
commit 8c1966ef4c
13 changed files with 1124 additions and 39 deletions
+68 -8
View File
@@ -15,6 +15,7 @@ using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
using WorkFlowCheck.DL.Entities;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Identity;
namespace WorkFlowCheck.BL.Services
{
@@ -30,6 +31,7 @@ namespace WorkFlowCheck.BL.Services
_mapper = mapper;
_configuration = configuration;
}
public async Task<UserDTO> GetUserAsync(int Id)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -48,7 +50,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<List<UserDTO>> GetAllUserAsync()
{
var retVal = new List<UserDTO>
@@ -72,7 +73,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public async Task<UserDTO> Authenticate(string userName, string password)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
@@ -113,7 +113,6 @@ namespace WorkFlowCheck.BL.Services
}
return retVal;
}
public string GenerateJwtToken(UserDTO userDTO)
{
var jwtSettings = _configuration.GetSection("Jwt");
@@ -144,13 +143,74 @@ namespace WorkFlowCheck.BL.Services
return new JwtSecurityTokenHandler().WriteToken(token);
}
public async Task<UserDTO> UpdateUserAsync(UserDTO userDTO)
{
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
if (userDTO.Id == 0)
{
var user = new User();
user.UserName = userDTO.UserName;
user.FirstName = userDTO.FirstName;
user.LastName = userDTO.LastName;
user.Email = userDTO.Email;
user.JwtToken = "";
public Task<UserDTO> UpdateUserAsync(UserDTO userDTO) => throw new NotImplementedException();
public Task<RoleDTO> GetRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<RoleDTO>> GetAllRoleAsync() => throw new NotImplementedException();
public Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
Task<UserRoleDTO> IUserService.GetUserRoleAsync(int Id) => throw new NotImplementedException();
user.PasswordHash = PasswordHasher.HashPassword(userDTO.Password);
_dbContext.Users.Add(user);
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
}
else
{
var user = await _dbContext.Users.Where(w => w.Id == userDTO.Id).FirstOrDefaultAsync();
if (user != null)
{
user.UserName = userDTO.UserName;
user.FirstName = userDTO.FirstName;
user.LastName = userDTO.LastName;
user.Email = userDTO.Email;
await _dbContext.SaveChangesAsync();
retVal = _mapper.Map<UserDTO>(user);
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<RoleDTO> GetRoleAsync(int Id) => throw new NotImplementedException();
public async Task<List<RoleDTO>> GetAllRoleAsync()
{
var retVal = new List<RoleDTO>();
try
{
var roles = await _dbContext.Roles.ToListAsync();
if (roles != null)
{
retVal = _mapper.Map<List<RoleDTO>>(roles);
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<RoleDTO> UpdateRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
public async Task<UserRoleDTO> GetUserRoleAsync(int Id) => throw new NotImplementedException();
public Task<List<UserRoleDTO>> GetAllUserRoleAsync() => throw new NotImplementedException();
public Task<UserRoleDTO> UpdateUserRoleAsync(RoleDTO roleDTO) => throw new NotImplementedException();
}
}
+6 -2
View File
@@ -136,7 +136,9 @@ namespace WorkFlowCheck.DL
CreatedBy = "System",
LastModAt = DateTime.UtcNow,
LastModBy = "System",
JwtToken = ""
JwtToken = "",
Active = true,
Token2FA = ""
},
new User
{
@@ -151,7 +153,9 @@ namespace WorkFlowCheck.DL
CreatedBy = "System",
LastModAt = DateTime.UtcNow,
LastModBy = "System",
JwtToken = ""
JwtToken = "",
Active = true,
Token2FA = ""
}
);
}
+2
View File
@@ -12,6 +12,8 @@ namespace WorkFlowCheck.DL.Entities
public string UserName { get; set; } = null!;
public string? PasswordHash { get; set; } = null;
public string JwtToken { get; set; } = null!;
public string Token2FA { get; set; } = null!;
public bool Active { get; set; }
public virtual ICollection<UserRole> UserRoles { get; set; } = new List<UserRole>();
@@ -0,0 +1,635 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using WorkFlowCheck.DL;
#nullable disable
namespace WorkFlowCheck.DL.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20250318104815_Extend004")]
partial class Extend004
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.12")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListHeader", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CheckListTemplateHeaderId")
.HasColumnType("int");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("DocumentNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid>("GuidNumber")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<bool>("IsStorno")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ShortName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.HasIndex("CheckListTemplateHeaderId");
b.ToTable("CheckListHeader", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListRow", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Answer")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("CheckListHeaderId")
.HasColumnType("int");
b.Property<int>("CheckListTemplateRowId")
.HasColumnType("int");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid>("GuidNumber")
.HasColumnType("uniqueidentifier");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<byte[]>("Photo")
.IsRequired()
.HasColumnType("varbinary(max)");
b.HasKey("Id");
b.HasIndex("CheckListHeaderId");
b.HasIndex("CheckListTemplateRowId");
b.ToTable("CheckListRow", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListTemplateHeader", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ShortName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("CheckListTemplateHeader", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListTemplateRow", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("AnswerType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("CheckListTemplateHeaderId")
.HasColumnType("int");
b.Property<int>("CheckPointId")
.HasColumnType("int");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("EquipmentId")
.HasColumnType("int");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("OperationDescription")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("RowIndex")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CheckListTemplateHeaderId");
b.HasIndex("CheckPointId");
b.HasIndex("EquipmentId");
b.ToTable("CheckListTemplateRow", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckPoint", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Code")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ShortName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("CheckPoint", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.Equipment", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EquipmentNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("ShortName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Equipment", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.Location", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FullName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Location", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.Role", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("RoleName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Roles", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.RoleCheckListTemplateHeader", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("CheckListTemplateHeaderId")
.HasColumnType("int");
b.Property<bool>("Enabled")
.HasColumnType("bit");
b.Property<int>("RoleId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("CheckListTemplateHeaderId");
b.HasIndex("RoleId");
b.ToTable("RoleCheckListTemplateHeader", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.User", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("Active")
.HasColumnType("bit");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FirstName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<string>("JwtToken")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("LastModAt")
.HasColumnType("datetime2");
b.Property<string>("LastModBy")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("Token2FA")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Users", (string)null);
b.HasData(
new
{
Id = 1,
Active = true,
CreatedAt = new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7867),
CreatedBy = "System",
Email = "admin@nuvolar.hu",
FirstName = "Administrator",
IsDeleted = false,
JwtToken = "",
LastModAt = new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7870),
LastModBy = "System",
LastName = "System",
PasswordHash = "eGM0NUREZnJ0ISFFRDIxMKE5TYwthDBuUsTUEO1fBnCR3VdSCmdz47ue0RoVvnkY",
Token2FA = "",
UserName = "admin"
},
new
{
Id = 2,
Active = true,
CreatedAt = new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9210),
CreatedBy = "System",
Email = "user@nuvolar.hu",
FirstName = "User",
IsDeleted = false,
JwtToken = "",
LastModAt = new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9212),
LastModBy = "System",
LastName = "System",
PasswordHash = "eGM0NUREZnJ0ISFFRDIxMPwM2D9sQSj7zmaSBIsOGe0I9hBFwCGPVbyrYMA5EnKG",
Token2FA = "",
UserName = "user"
});
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.UserRole", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int?>("RoleId")
.HasColumnType("int");
b.Property<int>("UserId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("RoleId");
b.HasIndex("UserId");
b.ToTable("UserRoles", (string)null);
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListHeader", b =>
{
b.HasOne("WorkFlowCheck.DL.Entities.CheckListTemplateHeader", "CheckListTemplateHeader")
.WithMany()
.HasForeignKey("CheckListTemplateHeaderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CheckListTemplateHeader");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListRow", b =>
{
b.HasOne("WorkFlowCheck.DL.Entities.CheckListHeader", "CheckListHeader")
.WithMany("CheckListRows")
.HasForeignKey("CheckListHeaderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WorkFlowCheck.DL.Entities.CheckListTemplateRow", "CheckListTemplateRow")
.WithMany()
.HasForeignKey("CheckListTemplateRowId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CheckListHeader");
b.Navigation("CheckListTemplateRow");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListTemplateRow", b =>
{
b.HasOne("WorkFlowCheck.DL.Entities.CheckListTemplateHeader", "CheckListTemplateHeader")
.WithMany("CheckListTemplateRows")
.HasForeignKey("CheckListTemplateHeaderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WorkFlowCheck.DL.Entities.CheckPoint", "CheckPoint")
.WithMany("CheckListTemplateRows")
.HasForeignKey("CheckPointId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WorkFlowCheck.DL.Entities.Equipment", "Equipment")
.WithMany()
.HasForeignKey("EquipmentId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CheckListTemplateHeader");
b.Navigation("CheckPoint");
b.Navigation("Equipment");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.RoleCheckListTemplateHeader", b =>
{
b.HasOne("WorkFlowCheck.DL.Entities.CheckListTemplateHeader", "CheckListTemplateHeader")
.WithMany()
.HasForeignKey("CheckListTemplateHeaderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("WorkFlowCheck.DL.Entities.Role", "Role")
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("CheckListTemplateHeader");
b.Navigation("Role");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.UserRole", b =>
{
b.HasOne("WorkFlowCheck.DL.Entities.Role", "Role")
.WithMany("UserRoles")
.HasForeignKey("RoleId");
b.HasOne("WorkFlowCheck.DL.Entities.User", "User")
.WithMany("UserRoles")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Role");
b.Navigation("User");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListHeader", b =>
{
b.Navigation("CheckListRows");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckListTemplateHeader", b =>
{
b.Navigation("CheckListTemplateRows");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.CheckPoint", b =>
{
b.Navigation("CheckListTemplateRows");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.Role", b =>
{
b.Navigation("UserRoles");
});
modelBuilder.Entity("WorkFlowCheck.DL.Entities.User", b =>
{
b.Navigation("UserRoles");
});
#pragma warning restore 612, 618
}
}
}
@@ -0,0 +1,69 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace WorkFlowCheck.DL.Migrations
{
/// <inheritdoc />
public partial class Extend004 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "Active",
table: "Users",
type: "bit",
nullable: false,
defaultValue: false);
migrationBuilder.AddColumn<string>(
name: "Token2FA",
table: "Users",
type: "nvarchar(max)",
nullable: false,
defaultValue: "");
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "Active", "CreatedAt", "LastModAt", "Token2FA" },
values: new object[] { true, new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7867), new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7870), "" });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "Active", "CreatedAt", "LastModAt", "Token2FA" },
values: new object[] { true, new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9210), new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9212), "" });
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Active",
table: "Users");
migrationBuilder.DropColumn(
name: "Token2FA",
table: "Users");
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 1,
columns: new[] { "CreatedAt", "LastModAt" },
values: new object[] { new DateTime(2025, 3, 12, 8, 8, 57, 555, DateTimeKind.Utc).AddTicks(6125), new DateTime(2025, 3, 12, 8, 8, 57, 555, DateTimeKind.Utc).AddTicks(6129) });
migrationBuilder.UpdateData(
table: "Users",
keyColumn: "Id",
keyValue: 2,
columns: new[] { "CreatedAt", "LastModAt" },
values: new object[] { new DateTime(2025, 3, 12, 8, 8, 57, 566, DateTimeKind.Utc).AddTicks(6128), new DateTime(2025, 3, 12, 8, 8, 57, 566, DateTimeKind.Utc).AddTicks(6129) });
}
}
}
@@ -398,6 +398,9 @@ namespace WorkFlowCheck.DL.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<bool>("Active")
.HasColumnType("bit");
b.Property<DateTime>("CreatedAt")
.HasColumnType("datetime2");
@@ -434,6 +437,10 @@ namespace WorkFlowCheck.DL.Migrations
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("Token2FA")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("UserName")
.IsRequired()
.HasColumnType("nvarchar(max)");
@@ -446,31 +453,35 @@ namespace WorkFlowCheck.DL.Migrations
new
{
Id = 1,
CreatedAt = new DateTime(2025, 3, 12, 8, 8, 57, 555, DateTimeKind.Utc).AddTicks(6125),
Active = true,
CreatedAt = new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7867),
CreatedBy = "System",
Email = "admin@nuvolar.hu",
FirstName = "Administrator",
IsDeleted = false,
JwtToken = "",
LastModAt = new DateTime(2025, 3, 12, 8, 8, 57, 555, DateTimeKind.Utc).AddTicks(6129),
LastModAt = new DateTime(2025, 3, 18, 10, 48, 13, 634, DateTimeKind.Utc).AddTicks(7870),
LastModBy = "System",
LastName = "System",
PasswordHash = "eGM0NUREZnJ0ISFFRDIxMKE5TYwthDBuUsTUEO1fBnCR3VdSCmdz47ue0RoVvnkY",
Token2FA = "",
UserName = "admin"
},
new
{
Id = 2,
CreatedAt = new DateTime(2025, 3, 12, 8, 8, 57, 566, DateTimeKind.Utc).AddTicks(6128),
Active = true,
CreatedAt = new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9210),
CreatedBy = "System",
Email = "user@nuvolar.hu",
FirstName = "User",
IsDeleted = false,
JwtToken = "",
LastModAt = new DateTime(2025, 3, 12, 8, 8, 57, 566, DateTimeKind.Utc).AddTicks(6129),
LastModAt = new DateTime(2025, 3, 18, 10, 48, 13, 645, DateTimeKind.Utc).AddTicks(9212),
LastModBy = "System",
LastName = "System",
PasswordHash = "eGM0NUREZnJ0ISFFRDIxMPwM2D9sQSj7zmaSBIsOGe0I9hBFwCGPVbyrYMA5EnKG",
Token2FA = "",
UserName = "user"
});
});
+2 -2
View File
@@ -5,6 +5,6 @@
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>Learn about <a href="https://learn.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
<h1 class="display-4">Üdvözlöm!</h1>
<p>WorkFlowCheck Tablet & WEB & API rendszer</a>.</p>
</div>
@@ -1,4 +1,90 @@
@page
@model WorkFlowCheck.Web.Pages.UserAndRole.RolePageModel
@{
ViewData["Title"] = "Szabályok";
}
<h1>@ViewData["Title"]</h1>
<div class="card shadow p-4">
<div class="d-flex justify-content-end">
<button id="newRoleBtn" class="btn btn-primary float-right new-btn">Új elem hozzáadása</button>
</div>
<table id="tbRolesPage" class="table table-bordered table-hover table-sm" style="width:100%">
<thead class="table-primary">
<tr>
<th>ID</th>
<th>Role Name</th>
<th class="text-center">Action</th>
</tr>
</thead>
<tfoot class="table-light">
<tr>
<th>ID</th>
<th>Role Name</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div>
@section Scripts {
<script>
const table = new DataTable('#tbRolesPage', {
ajax: {
url: "@Url.Page("./RolePage", "LoadRoles")",
type: "GET",
dataSrc : "data"
},
columns: [
{ data: "id" },
{ data: "roleName" },
{ data: null, render: function (data, type, row) {
return `<button class="btn btn-primary edit-btn" data-id="${row.id}">Módosítás</button>
<button class="btn btn-danger delete-btn" data-id="${row.id}">Törlés</button>
`;
}}
],
columnDefs: [
{
"targets": 0,
"visible": false
},
{
"targets": 2,
"className": "text-center",
"width": "15%"
}
],
processing:true
});
$('#newRoleBtn').on('click', function ()
{
console.log('New button clicked!"');
window.location.href = `@Url.Page("./RoleEditPage")?id=0`;
});
$('#tbRolesPage').on('click', '.edit-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
window.location.href = `@Url.Page("./RoleEditPage")?id=${row.id}`;
});
$('#tbRolesPage').on('click', '.delete-btn', function ()
{
const row = table.row($(this).closest('tr')).data();
console.log(row);
showConfirmModal({
title: 'Törlés megerősítése',
message: 'Biztosan törölni szeretnéd ezt az elemet?',
okText: 'Törlés',
cancelText: 'Mégsem'
}).then(function(result) {
if(result === 'ok') {
console.log('Törlés végrehajtva');
}
});
});
</script>
}
@@ -1,12 +1,25 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.UserAndRole
{
public class RolePageModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly IUserService _userService;
public RolePageModel(ILogger<IndexModel> logger, IUserService userService)
{
_logger = logger;
_userService = userService;
}
public void OnGet()
{
}
public async Task<JsonResult> OnGetLoadRoles()
{
var results = await _userService.GetAllRoles();
return new JsonResult(new { data = results });
}
}
}
@@ -15,11 +15,27 @@
<form method="post" id="UserForm">
<meta name="csrf-token" content="@Antiforgery.GetAndStoreTokens(HttpContext).RequestToken" />
<input type="hidden" asp-for="User.Id" />
<input type="hidden" asp-for="User.Password" value="" />
<input type="hidden" asp-for="User.JwtToken" value="" />
<input type="hidden" asp-for="User.RoleDTO" value="" />
<div class="mb-3">
<label asp-for="User.UserName"></label>
<input asp-for="User.UserName" class="form-control" />
<span asp-validation-for="User.UserName" class="text-danger"></span>
</div>
@if (Model.User.Id == 0)
{
<div class="mb-3">
<label asp-for="User.Password"></label>
<input asp-for="User.Password" class="form-control" type="password" />
<span asp-validation-for="User.Password" class="text-danger"></span>
</div>
}
<div class="mb-3">
<label asp-for="User.Email"></label>
<input asp-for="User.Email" class="form-control" />
<span asp-validation-for="User.Email" class="text-danger"></span>
</div>
<div class="mb-3">
<label asp-for="User.FirstName"></label>
<input asp-for="User.FirstName" class="form-control" />
@@ -45,6 +61,8 @@
var formData = getFormAsNestedObject('#UserForm');
const $form = $('#UserForm');
formData.User.RoleDTO=[];
if ($form.valid())
{
$.ajax({
@@ -1,6 +1,8 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Serilog;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.Web.Services;
using WorkFlowCheck.Web.Services.Interfaces;
namespace WorkFlowCheck.Web.Pages.UserAndRole
@@ -23,5 +25,26 @@ namespace WorkFlowCheck.Web.Pages.UserAndRole
{
User = await _userService.GetUser(id);
}
public async Task<IActionResult> OnPostSave([FromBody] UserDTO userDTO)
{
try
{
var result = await _userService.UpdateUser(userDTO);
if (result.IsSuccess)
{
return new JsonResult(new { success = true });
}
else
{
return new JsonResult(new { success = false });
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return new JsonResult(new { success = false });
}
}
}
@@ -6,16 +6,16 @@ namespace WorkFlowCheck.Web.Services.Interfaces
{
Task<UserDTO> GetUser(int id);
Task<List<UserDTO>> GetAllUsers();
Task<UserDTO> UpdateUser(UserDTO user);
Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO userDTO);
Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password);
Task<RoleDTO> GetRole(int id);
Task<List<RoleDTO>> GetAllRoles();
Task<RoleDTO> UpdateRole(RoleDTO role);
Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO roleDTO);
Task<UserRoleDTO> GetUserRole(int id);
Task<List<UserDTO>> GetAllUserRoles();
Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole);
Task<List<UserRoleDTO>> GetAllUserRoles();
Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO);
}
+181 -17
View File
@@ -11,6 +11,78 @@ namespace WorkFlowCheck.Web.Services
public UserService(HttpClient httpClient, IConfiguration configuration, IHttpContextAccessor httpContextAccessor) : base(httpClient, configuration, httpContextAccessor)
{
}
public async Task<UserDTO> GetUser(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetUser/{id}";
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<List<UserDTO>> GetAllUsers()
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUsers";
var retVal = new List<UserDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<UserDTO>> UpdateUser(UserDTO userDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/user/updateUser";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserDTO>>(jsonString);
return response ?? new ApiResponseDTO<UserDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<UserDTO>
{
IsSuccess = false
};
}
}
public async Task<ApiResponseDTO<UserDTO>> Authenticate(string username, string password)
{
try
@@ -49,15 +121,14 @@ namespace WorkFlowCheck.Web.Services
}
}
public Task<ApiRequestDTO<List<RoleDTO>>> GetAllRoles() => throw new NotImplementedException();
public Task<ApiRequestDTO<List<UserDTO>>> GetAllUserRoles() => throw new NotImplementedException();
public async Task<List<UserDTO>> GetAllUsers()
public async Task<RoleDTO> GetRole(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUsers";
var retVal = new List<UserDTO>();
string endpoint = $"{_httpClient.BaseAddress}api/Role/GetRole/{id}";
var retVal = new RoleDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserDTO>>>(endpoint);
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<RoleDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
@@ -72,15 +143,64 @@ namespace WorkFlowCheck.Web.Services
}
return retVal;
}
public async Task<List<RoleDTO>> GetAllRoles()
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllRoles";
var retVal = new List<RoleDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<RoleDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<RoleDTO>> UpdateRole(RoleDTO roleDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/user/updateRole";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, roleDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<RoleDTO>>(jsonString);
return response ?? new ApiResponseDTO<RoleDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<RoleDTO>
{
IsSuccess = false
};
}
}
public Task<RoleDTO> GetRole(int id) => throw new NotImplementedException();
public async Task<UserDTO> GetUser(int id)
public async Task<UserRoleDTO> GetUserRole(int id)
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetUser/{id}";
var retVal = new UserDTO() { RoleDTO = new List<RoleDTO>() };
string endpoint = $"{_httpClient.BaseAddress}api/UserRole/GetUserRole/{id}";
var retVal = new UserRoleDTO();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserRoleDTO>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
@@ -95,11 +215,55 @@ namespace WorkFlowCheck.Web.Services
}
return retVal;
}
public Task<UserRoleDTO> GetUserRole(int id) => throw new NotImplementedException();
public Task<RoleDTO> UpdateRole(RoleDTO role) => throw new NotImplementedException();
public Task<UserDTO> UpdateUser(UserDTO user) => throw new NotImplementedException();
public Task<UserRoleDTO> UpdateUserRole(UserRoleDTO userRole) => throw new NotImplementedException();
Task<List<RoleDTO>> IUserService.GetAllRoles() => throw new NotImplementedException();
Task<List<UserDTO>> IUserService.GetAllUserRoles() => throw new NotImplementedException();
public async Task<List<UserRoleDTO>> GetAllUserRoles()
{
string endpoint = $"{_httpClient.BaseAddress}api/User/GetAllUserRoles";
var retVal = new List<UserRoleDTO>();
try
{
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<List<UserRoleDTO>>>(endpoint);
if (response != null)
{
if (response.IsSuccess)
{
return response.Data;
}
}
}
catch (Exception ex)
{
Log.Error(ex.Message);
}
return retVal;
}
public async Task<ApiResponseDTO<UserRoleDTO>> UpdateUserRole(UserRoleDTO userRoleDTO)
{
try
{
string endpoint = $"{_httpClient.BaseAddress}api/user/updateUserRole";
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, userRoleDTO))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<UserRoleDTO>>(jsonString);
return response ?? new ApiResponseDTO<UserRoleDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<UserRoleDTO>
{
IsSuccess = false
};
}
}
}
}