Save AddOrEdit Jobs to group
This commit is contained in:
@@ -44,11 +44,18 @@ public interface IClassificationGroupRepository : IRepository<long, Classificati
|
||||
Task<bool> CheckIfEmployeeHasThisJob(long jobId, long groupId);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت مشاغل گروه توسط آی دی گروه
|
||||
/// ذخیر ایجاد یا ویرایش مشاغل در گروه
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<EditClassificationGroupJob>> GetGroupJobs(long groupId);
|
||||
Task<bool> SaveJobsToGroup(AddOrEditJobInGroupDto command);
|
||||
|
||||
/// <summary>
|
||||
/// دریافت مشاغل گروه توسط آی دی گروه
|
||||
/// </summary>
|
||||
/// <param name="groupId"></param>
|
||||
/// <returns></returns>
|
||||
Task<List<EditClassificationGroupJob>> GetGroupJobs(long groupId);
|
||||
|
||||
/// <summary>
|
||||
/// چک میکند که آی پرسنلی وجود دارد که این شغل به او نسبت داده شده
|
||||
|
||||
@@ -225,6 +225,13 @@ public interface IClassificationSchemeApplication
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> CheckIfEmployeeHasThisJob(long jobId, long groupId);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ذخیر ایجاد یا ویرایش مشاغل در گروه
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
Task<OperationResult> SaveJobsToGroup(AddOrEditJobInGroupDto command);
|
||||
#endregion
|
||||
|
||||
}
|
||||
@@ -633,4 +633,14 @@ public class ClassificationSchemeApplication : IClassificationSchemeApplication
|
||||
|
||||
return op.Succcedded(-1, "حذف با موفقیت انجام شد");
|
||||
}
|
||||
|
||||
public async Task<OperationResult> SaveJobsToGroup(AddOrEditJobInGroupDto command)
|
||||
{
|
||||
var op = new OperationResult();
|
||||
var res= await _classificationGroupRepository.SaveJobsToGroup(command);
|
||||
if (!res)
|
||||
return op.Failed("خطا در انجام عملیات");
|
||||
|
||||
return op.Succcedded();
|
||||
}
|
||||
}
|
||||
@@ -224,5 +224,73 @@ public class ClassificationGroupRepository : RepositoryBase<long, Classification
|
||||
return await _context.ClassificationEmployees.AnyAsync(x =>
|
||||
x.ClassificationGroupJobId == id && x.ClassificationGroupId == groupId);
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> SaveJobsToGroup(AddOrEditJobInGroupDto command)
|
||||
{
|
||||
var newJoblist = new List<ClassificationGroupJob>();
|
||||
var alreadyExitjobs = new List<ClassificationGroupJob>();
|
||||
var alreadyAdded = await _context.ClassificationGroups.Where(x => x.id == command.GroupId)
|
||||
.Include(x => x.ClassificationGroupJobs).FirstOrDefaultAsync();
|
||||
if (command.AddJobListDto.Count > 0)
|
||||
{
|
||||
var addedJobsIds = command.AddJobListDto.Where(x => x.JobId > 0).Select(x => x.JobId).ToList();
|
||||
var getJobs = _context.Jobs.Where(x => addedJobsIds.Contains(x.id));
|
||||
|
||||
foreach (var item in getJobs)
|
||||
{
|
||||
|
||||
var newJob = new ClassificationGroupJob(item.id, item.JobName, item.JobCode, command.GroupId,
|
||||
$"{command.GroupNoInt}");
|
||||
|
||||
if (alreadyAdded.ClassificationGroupJobs.Any(x => x.JobId == item.id))
|
||||
{
|
||||
alreadyExitjobs.Add(newJob);
|
||||
}
|
||||
else
|
||||
{
|
||||
newJoblist.Add(newJob);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (alreadyAdded.ClassificationGroupJobs.Count == 0)
|
||||
{
|
||||
|
||||
if (command.AddJobListDto.Count > 0)
|
||||
{
|
||||
|
||||
await _context.ClassificationGroupJobs.AddRangeAsync(newJoblist);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
|
||||
var alreadyExitJobsIds = alreadyExitjobs.Select(x => x.JobId).ToList();
|
||||
|
||||
var toBeRemove = alreadyAdded.ClassificationGroupJobs.Where(x => !alreadyExitJobsIds.Contains(x.JobId))
|
||||
.ToList();
|
||||
if (toBeRemove.Count > 0)
|
||||
{
|
||||
_context.ClassificationGroupJobs.RemoveRange(toBeRemove);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
if (newJoblist.Count > 0)
|
||||
{
|
||||
await _context.ClassificationGroupJobs.AddRangeAsync(newJoblist);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -149,6 +149,16 @@ public class ClassificationSchemeController : AdminBaseController
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ذخیره افزودن یا ویرایش مشاغل گروه
|
||||
/// </summary>
|
||||
/// <param name="command"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("SaveJobsToGroup")]
|
||||
public async Task<ActionResult<OperationResult>> SaveJobsToGroup(AddOrEditJobInGroupDto command)
|
||||
{
|
||||
var result = await _classificationSchemeApplication.SaveJobsToGroup(command);
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user