示例#1
0
        public async Task <ApiResponse> Handle(DeleteCandidateDetailCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                HiringRequestCandidates    projectCandidateDetail = new HiringRequestCandidates();
                ProjectHiringRequestDetail hrDetail = new ProjectHiringRequestDetail();
                if (request.HiringRequestId != 0)
                {
                    projectCandidateDetail = await _dbContext.HiringRequestCandidates
                                             .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                                  x.HiringRequestId == request.HiringRequestId &&
                                                                  x.CandidateId == request.CandidateId);

                    if (projectCandidateDetail != null)
                    {
                        projectCandidateDetail.IsDeleted    = true;
                        projectCandidateDetail.ModifiedById = request.ModifiedById;
                        projectCandidateDetail.ModifiedDate = request.ModifiedDate;
                        await _dbContext.SaveChangesAsync();

                        // note: to update filled vacancire in hiring request detail page

                        hrDetail = await _dbContext.ProjectHiringRequestDetail
                                   .FirstOrDefaultAsync(x => x.HiringRequestId == request.HiringRequestId &&
                                                        x.IsDeleted == false);

                        if (hrDetail == null)
                        {
                            throw new Exception("Hiring Job not found");
                        }
                        int count = await _dbContext.HiringRequestCandidates
                                    .CountAsync(x => x.HiringRequestId == request.HiringRequestId &&
                                                x.IsDeleted == false &&
                                                x.IsSelected);

                        hrDetail.FilledVacancies = count;
                        hrDetail.ModifiedById    = request.ModifiedById;
                        hrDetail.ModifiedDate    = request.ModifiedDate;
                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        throw new Exception("No Candidate found");
                    }
                }
                response.ResponseData = hrDetail;
                response.StatusCode   = StaticResource.successStatusCode;
                response.Message      = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(AddHiringRequestCandidateCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                var employeeExist = await _dbContext.HiringRequestCandidates
                                    .FirstOrDefaultAsync(x => x.EmployeeID == request.EmployeeID &&
                                                         x.HiringRequestId == request.HiringRequestId &&
                                                         x.IsDeleted == false);

                if (employeeExist == null)
                {
                    HiringRequestCandidates candidateDeatil = new HiringRequestCandidates()
                    {
                        HiringRequestId = request.HiringRequestId,
                        EmployeeID      = request.EmployeeID,
                        CreatedById     = request.CreatedById,
                        CreatedDate     = request.CreatedDate,
                        IsDeleted       = false,
                    };
                    await _dbContext.HiringRequestCandidates.AddAsync(candidateDeatil);

                    await _dbContext.SaveChangesAsync();
                }
                else
                {
                    throw new Exception("Candidate already exists with a job in project");
                }
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }
        public async Task <ApiResponse> Handle(HiringRequestSelectCandidateCommand request, CancellationToken cancellationToken)
        {
            ApiResponse response = new ApiResponse();

            try
            {
                if (request != null)
                {
                    HiringRequestCandidates hiringRequestCandidates = await _dbContext.HiringRequestCandidates
                                                                      .FirstOrDefaultAsync(x => x.IsDeleted == false &&
                                                                                           x.EmployeeID == request.EmployeeId &&
                                                                                           x.HiringRequestId == request.HiringRequestId);

                    if (hiringRequestCandidates != null)
                    {
                        hiringRequestCandidates.IsSelected   = true;
                        hiringRequestCandidates.ModifiedById = request.ModifiedById;
                        hiringRequestCandidates.ModifiedDate = request.ModifiedDate;
                        hiringRequestCandidates.IsDeleted    = false;
                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        throw new Exception("Candidate not found");
                    }

                    //update the hiring request table when candidate is selected

                    ProjectHiringRequestDetail hrDetail = await _dbContext.ProjectHiringRequestDetail
                                                          .FirstOrDefaultAsync(x => x.HiringRequestId == request.HiringRequestId &&
                                                                               x.IsDeleted == false);

                    if (hrDetail != null)
                    {
                        int count = await _dbContext.HiringRequestCandidates.Where(x => x.HiringRequestId == request.HiringRequestId &&
                                                                                   x.IsDeleted == false).CountAsync(x => x.IsSelected);

                        hrDetail.FilledVacancies = count;
                        await _dbContext.SaveChangesAsync();
                    }
                    else
                    {
                        throw new Exception("Hiring Job not found");
                    }
                    EmployeeSalaryAnalyticalInfo analyticalInfo = new EmployeeSalaryAnalyticalInfo();

                    analyticalInfo.IsDeleted       = false;
                    analyticalInfo.CreatedById     = request.CreatedById;
                    analyticalInfo.CreatedDate     = request.CreatedDate;
                    analyticalInfo.EmployeeID      = request.EmployeeId;
                    analyticalInfo.BudgetlineId    = request.BudgetLineId;
                    analyticalInfo.ProjectId       = request.ProjectId;
                    analyticalInfo.HiringRequestId = request.HiringRequestId;
                    await _dbContext.EmployeeSalaryAnalyticalInfo.AddAsync(analyticalInfo);

                    await _dbContext.SaveChangesAsync();

                    response.ResponseData = hrDetail;
                }
                response.StatusCode = StaticResource.successStatusCode;
                response.Message    = "Success";
            }
            catch (Exception ex)
            {
                response.StatusCode = StaticResource.failStatusCode;
                response.Message    = ex.Message;
            }
            return(response);
        }