changes
This commit is contained in:
@@ -15,6 +15,6 @@ namespace AccountManagement.Application.Contracts.SubAccount
|
||||
public string PhoneNumber { get; set; }
|
||||
public string Username { get; set; }
|
||||
public string ProfilePhoto { get; set; }
|
||||
public List<long> WorkshopIds { get; set; }
|
||||
//public List<long> WorkshopIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,6 @@ namespace AccountManagement.Application.Contracts.SubAccount
|
||||
public string Title { get; set; }
|
||||
public long AccountId { get; set; }
|
||||
public List<int> Permissions { get; set; }
|
||||
public List<long> WorkshopIds { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace AccountManagement.Application.Contracts.SubAccount
|
||||
public string PhoneNumber { get; set; }
|
||||
public string RePassword { get; set; }
|
||||
public long SubAccountRoleId { get; set; }
|
||||
public List<long> WorkshopIds { get; set; }
|
||||
//public List<long> WorkshopIds { get; set; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -113,12 +113,12 @@ namespace AccountManagement.Application
|
||||
if (cmd.PhoneNumber.Length != 11)
|
||||
return op.Failed("شماره تلفن همراه نامعتبر است");
|
||||
|
||||
if (!cmd.WorkshopIds.Any())
|
||||
return op.Failed("حداقل یک کارگاه را انتخاب کنید");
|
||||
//if (!cmd.WorkshopIds.Any())
|
||||
// return op.Failed("حداقل یک کارگاه را انتخاب کنید");
|
||||
|
||||
|
||||
if (!cmd.WorkshopIds.All(x => accountWorkshopsList.Contains(x)))
|
||||
return op.Failed("خطای سیستمی");
|
||||
//if (!cmd.WorkshopIds.All(x => accountWorkshopsList.Contains(x)))
|
||||
// return op.Failed("خطای سیستمی");
|
||||
|
||||
|
||||
if (cmd.SubAccountRoleId == 0 || !_subAccountRoleRepository.Exists(x => cmd.SubAccountRoleId == x.id))
|
||||
@@ -131,6 +131,10 @@ namespace AccountManagement.Application
|
||||
_cameraAccountRepository.Exists(x => x.Username == cmd.Username))
|
||||
return op.Failed("نام کاربری نمی تواند تکراری باشد");
|
||||
|
||||
var role = _subAccountRoleRepository.Get(cmd.SubAccountRoleId);
|
||||
var workshopId = role.RoleWorkshops.Select(x => x.WorkshopId).ToList();
|
||||
|
||||
|
||||
var entity = new SubAccount(cmd.AccountId, cmd.SubAccountRoleId, cmd.NationalCode, cmd.FName, cmd.LName, cmd.PhoneNumber, cmd.Username, _passwordHasher.Hash(cmd.Password),
|
||||
cmd.ProfilePhoto);
|
||||
|
||||
@@ -142,7 +146,7 @@ namespace AccountManagement.Application
|
||||
_subAccountRepository.SaveChanges();
|
||||
|
||||
|
||||
var workshops = cmd.WorkshopIds.Select(x => new WorkshopSubAccount(x, entity.id));
|
||||
var workshops = workshopId.Select(x => new WorkshopSubAccount(x, entity.id));
|
||||
|
||||
foreach (var w in workshops)
|
||||
_workshopSubAccountRepository.Create(w);
|
||||
@@ -175,22 +179,22 @@ namespace AccountManagement.Application
|
||||
|
||||
|
||||
|
||||
if (!cmd.WorkshopIds.All(x => accountWorkshopsList.Contains(x)))
|
||||
return op.Failed("خطای سیستمی");
|
||||
//if (!cmd.WorkshopIds.All(x => accountWorkshopsList.Contains(x)))
|
||||
// return op.Failed("خطای سیستمی");
|
||||
|
||||
|
||||
if (cmd.SubAccountRoleId == 0 || !_subAccountRoleRepository.Exists(x => cmd.SubAccountRoleId == x.id))
|
||||
return op.Failed("نقش مورد نظر وجود ندارد");
|
||||
|
||||
var workshopSubAccounts = _workshopSubAccountRepository.GetWorkshopsSubAccountEntityBySubAccountId(entity.id);
|
||||
foreach (var workshopSubAccount in workshopSubAccounts)
|
||||
_workshopSubAccountRepository.Remove(workshopSubAccount);
|
||||
//var workshopSubAccounts = _workshopSubAccountRepository.GetWorkshopsSubAccountEntityBySubAccountId(entity.id);
|
||||
//foreach (var workshopSubAccount in workshopSubAccounts)
|
||||
// _workshopSubAccountRepository.Remove(workshopSubAccount);
|
||||
|
||||
|
||||
var workshops = cmd.WorkshopIds.Select(x => new WorkshopSubAccount(x, entity.id));
|
||||
//var workshops = cmd.WorkshopIds.Select(x => new WorkshopSubAccount(x, entity.id));
|
||||
|
||||
foreach (var w in workshops)
|
||||
_workshopSubAccountRepository.Create(w);
|
||||
//foreach (var w in workshops)
|
||||
// _workshopSubAccountRepository.Create(w);
|
||||
|
||||
entity.Edit(cmd.SubAccountRoleId, cmd.NationalCode, cmd.FName, cmd.LName, cmd.ProfilePhoto);
|
||||
_workshopSubAccountRepository.SaveChanges();
|
||||
@@ -241,7 +245,7 @@ namespace AccountManagement.Application
|
||||
OperationResult op = new();
|
||||
if (_subAccountRoleRepository.Exists(x => x.AccountId == command.AccountId && x.Title.Trim() == command.Title.Trim()))
|
||||
return op.Failed("یک نقش با این عنوان وجود دارد");
|
||||
var role = new SubAccountRole(command.Title, command.Permissions, command.AccountId);
|
||||
var role = new SubAccountRole(command.Title, command.Permissions, command.AccountId,command.WorkshopIds);
|
||||
_subAccountRoleRepository.Create(role);
|
||||
_subAccountRoleRepository.SaveChanges();
|
||||
return op.Succcedded(role.id);
|
||||
@@ -254,8 +258,24 @@ namespace AccountManagement.Application
|
||||
var entity = _subAccountRoleRepository.Get(cmd.Id);
|
||||
if (entity == null)
|
||||
return op.Failed(ApplicationMessages.RecordNotFound);
|
||||
entity.Edit(cmd.Title, cmd.Permissions);
|
||||
_subAccountRoleRepository.SaveChanges();
|
||||
entity.Edit(cmd.Title, cmd.Permissions,cmd.WorkshopIds);
|
||||
|
||||
var subAccountRoles = _subAccountRepository.GetBySubAccountRole(cmd.Id);
|
||||
|
||||
foreach (var subAccount in subAccountRoles)
|
||||
{
|
||||
var workshopSubAccounts = _workshopSubAccountRepository.GetWorkshopsSubAccountEntityBySubAccountId(subAccount.id);
|
||||
foreach (var workshopSubAccount in workshopSubAccounts)
|
||||
_workshopSubAccountRepository.Remove(workshopSubAccount);
|
||||
|
||||
|
||||
var workshops = cmd.WorkshopIds.Select(x => new WorkshopSubAccount(x, subAccount.id));
|
||||
|
||||
foreach (var w in workshops)
|
||||
_workshopSubAccountRepository.Create(w);
|
||||
}
|
||||
|
||||
_subAccountRoleRepository.SaveChanges();
|
||||
return op.Succcedded();
|
||||
}
|
||||
public OperationResult AssignRoleToSubAccount(AssignSubAccountRole command)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using _0_Framework.Domain;
|
||||
using AccountManagement.Application.Contracts.SubAccount;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace AccountManagement.Domain.SubAccountAgg
|
||||
{
|
||||
@@ -13,5 +14,6 @@ namespace AccountManagement.Domain.SubAccountAgg
|
||||
SubAccount GetDetails(long subAccountId);
|
||||
SubAccount GetBy(string commandUsername);
|
||||
SubAccountViewModel GetByVerifyCodeAndPhoneNumber(string code, string phone);
|
||||
List<SubAccount> GetBySubAccountRole(long subAccountRoleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,17 +13,21 @@ namespace AccountManagement.Domain.SubAccountRoleAgg
|
||||
|
||||
public List<SubAccountRolePermission> RolePermissions { get; private set; }
|
||||
public List<SubAccount> SubAccounts { get; private set; }
|
||||
public List<SubAccountRoleWorkshop> RoleWorkshops { get; set; }
|
||||
|
||||
private SubAccountRole()
|
||||
{
|
||||
}
|
||||
|
||||
public SubAccountRole(string title, List<int> permissions, long accountId)
|
||||
public SubAccountRole(string title, List<int> permissions, long accountId, List<long> workshopIds)
|
||||
{
|
||||
Title = title;
|
||||
RolePermissions = permissions.Select(x => new SubAccountRolePermission(x, id)).ToList();
|
||||
AccountId = accountId;
|
||||
RoleWorkshops = workshopIds.Select(x => new SubAccountRoleWorkshop(x, id)).ToList();
|
||||
|
||||
}
|
||||
|
||||
public void ChangeTitle(string title)
|
||||
{
|
||||
Title = title;
|
||||
@@ -32,10 +36,12 @@ namespace AccountManagement.Domain.SubAccountRoleAgg
|
||||
{
|
||||
RolePermissions.AddRange(permissionIds.Select(x => new SubAccountRolePermission(x, id)));
|
||||
}
|
||||
public void Edit(string title, List<int> permissions)
|
||||
public void Edit(string title, List<int> permissions,List<long> workshopIds)
|
||||
{
|
||||
Title = title;
|
||||
RolePermissions = permissions.Select(x => new SubAccountRolePermission(x, id)).ToList();
|
||||
}
|
||||
}
|
||||
RoleWorkshops = workshopIds.Select(x => new SubAccountRoleWorkshop(x, id)).ToList();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using _0_Framework.Domain;
|
||||
|
||||
namespace AccountManagement.Domain.SubAccountRoleAgg;
|
||||
|
||||
public class SubAccountRoleWorkshop:EntityBase
|
||||
{
|
||||
public SubAccountRoleWorkshop(long workshopId, long subAccountId)
|
||||
{
|
||||
WorkshopId = workshopId;
|
||||
SubAccountId = subAccountId;
|
||||
}
|
||||
|
||||
public long WorkshopId { get; set; }
|
||||
public long SubAccountId { get; set; }
|
||||
public SubAccountRole SubAccountRole { get; set; }
|
||||
}
|
||||
@@ -21,6 +21,10 @@ namespace AccountMangement.Infrastructure.EFCore.Mappings
|
||||
opt.WithOwner(x => x.SubAccountRole);
|
||||
});
|
||||
|
||||
builder.OwnsMany(x => x.RoleWorkshops, roleWorkshop =>
|
||||
{
|
||||
roleWorkshop.WithOwner(x => x.SubAccountRole).HasForeignKey(x => x.SubAccountId);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1303
AccountMangement.Infrastructure.EFCore/Migrations/20250530133036_add workshop to subAccountRole.Designer.cs
generated
Normal file
1303
AccountMangement.Infrastructure.EFCore/Migrations/20250530133036_add workshop to subAccountRole.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace AccountMangement.Infrastructure.EFCore.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class addworkshoptosubAccountRole : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "SubAccountRoleWorkshop",
|
||||
columns: table => new
|
||||
{
|
||||
id = table.Column<long>(type: "bigint", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
SubAccountId = table.Column<long>(type: "bigint", nullable: false),
|
||||
WorkshopId = table.Column<long>(type: "bigint", nullable: false),
|
||||
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_SubAccountRoleWorkshop", x => new { x.SubAccountId, x.id });
|
||||
table.ForeignKey(
|
||||
name: "FK_SubAccountRoleWorkshop_SubAccountRoles_SubAccountId",
|
||||
column: x => x.SubAccountId,
|
||||
principalTable: "SubAccountRoles",
|
||||
principalColumn: "id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "SubAccountRoleWorkshop");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1078,6 +1078,33 @@ namespace AccountMangement.Infrastructure.EFCore.Migrations
|
||||
|
||||
modelBuilder.Entity("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRole", b =>
|
||||
{
|
||||
b.OwnsMany("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRoleWorkshop", "RoleWorkshops", b1 =>
|
||||
{
|
||||
b1.Property<long>("SubAccountId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.Property<long>("id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("bigint");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b1.Property<long>("id"));
|
||||
|
||||
b1.Property<DateTime>("CreationDate")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b1.Property<long>("WorkshopId")
|
||||
.HasColumnType("bigint");
|
||||
|
||||
b1.HasKey("SubAccountId", "id");
|
||||
|
||||
b1.ToTable("SubAccountRoleWorkshop");
|
||||
|
||||
b1.WithOwner("SubAccountRole")
|
||||
.HasForeignKey("SubAccountId");
|
||||
|
||||
b1.Navigation("SubAccountRole");
|
||||
});
|
||||
|
||||
b.OwnsMany("AccountManagement.Domain.SubAccountRoleAgg.SubAccountRolePermission", "RolePermissions", b1 =>
|
||||
{
|
||||
b1.Property<long>("id")
|
||||
@@ -1105,6 +1132,8 @@ namespace AccountMangement.Infrastructure.EFCore.Migrations
|
||||
});
|
||||
|
||||
b.Navigation("RolePermissions");
|
||||
|
||||
b.Navigation("RoleWorkshops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("AccountManagement.Domain.TaskAgg.Tasks", b =>
|
||||
|
||||
@@ -77,5 +77,10 @@ namespace AccountMangement.Infrastructure.EFCore.Repository
|
||||
Username = entity.Username
|
||||
};
|
||||
}
|
||||
|
||||
public List<SubAccount> GetBySubAccountRole(long subAccountRoleId)
|
||||
{
|
||||
return _context.SubAccounts.Where(x => x.SubAccountRoleId == subAccountRoleId).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,13 +35,13 @@
|
||||
<div class="row customHeight">
|
||||
|
||||
<div class="col-12 my-1">
|
||||
<div class="from-group position-relative my-1">
|
||||
@* <div class="from-group position-relative my-1">
|
||||
<span class="spanTitleText">کارگاه</span>
|
||||
<div class="select-workshop-alert">
|
||||
<select class="form-select select2OptionWorkshop" aria-label="انتخاب کارگاه ..." asp-for="@Model.WorkshopIds" id="workshopSelect" multiple>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div> *@
|
||||
<div class="from-group position-relative my-1">
|
||||
<span class="spanTitleText">نقش</span>
|
||||
<div class="select-role-alert">
|
||||
|
||||
@@ -37,13 +37,13 @@
|
||||
|
||||
<input type="hidden" name="Command.SubAccountId" value="@Model.Id" placeholder="SubAccountId">
|
||||
|
||||
<div class="from-group position-relative my-2">
|
||||
@* <div class="from-group position-relative my-2">
|
||||
<span class="spanTitleText">کارگاه</span>
|
||||
<div class="select-workshop-alert">
|
||||
<select class="form-select select2OptionWorkshop" aria-label="انتخاب کارگاه ..." name="Command.WorkshopIds" id="workshopSelect" multiple>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div> *@
|
||||
<div class="from-group position-relative my-2">
|
||||
<span class="spanTitleText">نقش</span>
|
||||
<div class="select-role-alert">
|
||||
|
||||
@@ -291,8 +291,14 @@ function SaveDataAjax() {
|
||||
}, 3500);
|
||||
return;
|
||||
}
|
||||
|
||||
var workshops = [];
|
||||
const checkedWorkshops = $('input[name="WorkshopIds[]"]:checked');
|
||||
checkedWorkshops.each(function () {
|
||||
if (this.checked || this.indeterminate) {
|
||||
const number = Number(this.id.split("_")[1]);
|
||||
workshops.push(number);
|
||||
}
|
||||
});
|
||||
|
||||
if (checkedWorkshops.length === 0) {
|
||||
$('.alert-msg').show();
|
||||
@@ -325,9 +331,9 @@ function SaveDataAjax() {
|
||||
|
||||
var data = {
|
||||
Title: Title.val(),
|
||||
Permissions: selectedPermissions
|
||||
Permissions: selectedPermissions,
|
||||
WorkshopIds: workshops
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
async: false,
|
||||
dataType: 'json',
|
||||
|
||||
@@ -258,7 +258,7 @@ function SaveDataAjax() {
|
||||
var loading = $('#createData .spinner-loading');
|
||||
|
||||
|
||||
var workshopSelect = $('#workshopSelect').val();
|
||||
/* var workshopSelect = $('#workshopSelect').val();*/
|
||||
var roleSelect = $('#roleSelect').val();
|
||||
var nationalCode = $('#NationalCode');
|
||||
var fName = $('#FName');
|
||||
@@ -268,17 +268,17 @@ function SaveDataAjax() {
|
||||
var password = $('#Password');
|
||||
|
||||
|
||||
if (workshopSelect.length === 0) {
|
||||
$('.alert-msg').show();
|
||||
$('.alert-msg p').text('لطفا کارگاه را مشخص نمائید.');
|
||||
$('.select-workshop-alert').addClass('errored');
|
||||
setTimeout(function () {
|
||||
$('.alert-msg').hide();
|
||||
$('.alert-msg p').text('');
|
||||
$('.select-workshop-alert').removeClass('errored');
|
||||
}, 3500);
|
||||
return;
|
||||
}
|
||||
//if (workshopSelect.length === 0) {
|
||||
// $('.alert-msg').show();
|
||||
// $('.alert-msg p').text('لطفا کارگاه را مشخص نمائید.');
|
||||
// $('.select-workshop-alert').addClass('errored');
|
||||
// setTimeout(function () {
|
||||
// $('.alert-msg').hide();
|
||||
// $('.alert-msg p').text('');
|
||||
// $('.select-workshop-alert').removeClass('errored');
|
||||
// }, 3500);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (roleSelect === "0") {
|
||||
$('.alert-msg').show();
|
||||
|
||||
@@ -28,7 +28,7 @@ $(".select2OptionRole").select2({
|
||||
|
||||
|
||||
$(document).ready(function() {
|
||||
ajaxWorkshops();
|
||||
//ajaxWorkshops();
|
||||
ajaxRoles();
|
||||
});
|
||||
|
||||
@@ -150,7 +150,7 @@ function SaveDataAjax() {
|
||||
var loading = $('#createData .spinner-loading');
|
||||
|
||||
|
||||
var workshopSelect = $('#workshopSelect').val();
|
||||
/* var workshopSelect = $('#workshopSelect').val();*/
|
||||
var roleSelect = $('#roleSelect').val();
|
||||
var nationalCode = $('#NationalCode');
|
||||
var fName = $('#FName');
|
||||
@@ -159,17 +159,17 @@ function SaveDataAjax() {
|
||||
var username = $('#Username');
|
||||
var password = $('#Password');
|
||||
|
||||
if (workshopSelect.length === 0) {
|
||||
$('.alert-msg').show();
|
||||
$('.alert-msg p').text('لطفا کارگاه را مشخص نمائید.');
|
||||
$('.select-workshop-alert').addClass('errored');
|
||||
setTimeout(function () {
|
||||
$('.alert-msg').hide();
|
||||
$('.alert-msg p').text('');
|
||||
$('.select-workshop-alert').removeClass('errored');
|
||||
}, 3500);
|
||||
return;
|
||||
}
|
||||
//if (workshopSelect.length === 0) {
|
||||
// $('.alert-msg').show();
|
||||
// $('.alert-msg p').text('لطفا کارگاه را مشخص نمائید.');
|
||||
// $('.select-workshop-alert').addClass('errored');
|
||||
// setTimeout(function () {
|
||||
// $('.alert-msg').hide();
|
||||
// $('.alert-msg p').text('');
|
||||
// $('.select-workshop-alert').removeClass('errored');
|
||||
// }, 3500);
|
||||
// return;
|
||||
//}
|
||||
|
||||
if (roleSelect === '0') {
|
||||
$('.alert-msg').show();
|
||||
|
||||
Reference in New Issue
Block a user