public async Task <Result <int> > Handle(DeleteRecruitmentCommand command, CancellationToken cancellationToken)
            {
                var userName = _authenticatedUser.Username;
                var user     = await _userManager.FindByNameAsync(userName);

                var rolesList = await _userManager.GetRolesAsync(user).ConfigureAwait(false);

                var item = await _repository.GetByIdAsync(command.Id);


                if (item != null && (rolesList.Contains("Admin") || rolesList.Contains("SuperAdmin") || userName == item.UserName))
                {
                    var listrecruitmentBenefit = _recruitmentBenefitRepository.RecruitmentBenefits.Where(s => s.RecruitmentId == item.Id).ToList();
                    foreach (var _item in listrecruitmentBenefit)
                    {
                        await _recruitmentBenefitRepository.DeleteAsync(_item);
                    }
                    await _repository.DeleteAsync(item);

                    await _unitOfWork.Commit(cancellationToken);

                    return(Result <int> .Success(item.Id));
                }

                return(Result <int> .Fail("Lỗi!!!"));
            }
            public async Task <Result <RecruitmentResponse> > Handle(GetRecruitmentByIdQuery query, CancellationToken cancellationToken)
            {
                var item = await _repository.GetByIdAsync(query.Id);

                var mappedCategory = _mapper.Map <RecruitmentResponse>(item);

                mappedCategory.CompanyName = item.Company.Name;
                return(Result <RecruitmentResponse> .Success(mappedCategory));
            }
Esempio n. 3
0
        public async Task <Result <int> > Handle(ChangeStatusRecruitmentCommand request, CancellationToken cancellationToken)
        {
            var userName = _authenticatedUser.Username;
            var user     = await _userManager.FindByNameAsync(userName);

            var rolesList = await _userManager.GetRolesAsync(user).ConfigureAwait(false);

            var item = await _repository.GetByIdAsync(request.Id);

            if (item == null || !(rolesList.Contains("Admin") || rolesList.Contains("SuperAdmin") || userName == item.UserName))
            {
                return(Result <int> .Fail($"Lỗi!"));
            }
            else
            {
                item.Status = request.Status >= 0 ? request.Status : item.Status;
                await _repository.UpdateAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        }
        public async Task <Result <int> > Handle(UpdateRecruitmentCommand command, CancellationToken cancellationToken)
        {
            var userName = _authenticatedUser.Username;
            var user     = await _userManager.FindByNameAsync(userName);

            var rolesList = await _userManager.GetRolesAsync(user).ConfigureAwait(false);

            var item = await _repository.GetByIdAsync(command.Id);

            if (item == null || !(rolesList.Contains("Admin") || rolesList.Contains("SuperAdmin") || userName == item.UserName))
            {
                return(Result <int> .Fail($"Lỗi!"));
            }
            else
            {
                CultureInfo provider = CultureInfo.InvariantCulture;

                var place = item.Place;
                place.PlaceName  = command.PlaceName ?? place.PlaceName;
                place.ProvinceId = command.ProvinceId ?? place.ProvinceId;
                place.DistrictId = command.DistrictId ?? place.DistrictId;
                place.Latitude   = command.Latitude ?? place.Latitude;
                place.Longitude  = command.Longitude ?? place.Longitude;



                var item_CompanyIndustries = item.RecruitmentBenefit;
                foreach (var item_ in item_CompanyIndustries)
                {
                    await _recruitmentBenefitRepository.DeleteAsync(item_);
                }

                if (command.ListBenefit != null)
                {
                    foreach (var _item in command.ListBenefit)
                    {
                        try
                        {
                            RecruitmentBenefit tmp = new RecruitmentBenefit {
                                BenefitId = _item.BenefitId, Name = _item.Name, RecruitmentId = item.Id
                            };
                            await _recruitmentBenefitRepository.InsertAsync(tmp);
                        }
                        catch
                        {
                        }
                    }
                }



                item.Name               = command.Name ?? item.Name;
                item.Description        = command.Description ?? item.Description;
                item.Image              = command.Image ?? item.Image;
                item.JobTypeId          = command.JobTypeId ?? item.JobTypeId;
                item.JobNameId          = command.JobNameId ?? item.JobNameId;
                item.JobPositionId      = command.JobPositionId ?? item.JobPositionId;
                item.SalaryId           = command.SalaryId ?? item.SalaryId;
                item.ExperienceId       = command.ExperienceId ?? item.ExperienceId;
                item.GenderId           = command.GenderId ?? item.GenderId;
                item.JobAgeId           = command.JobAgeId ?? item.JobAgeId;
                item.DegreeId           = command.DegreeId ?? item.DegreeId;
                item.OtherRequirement   = command.OtherRequirement ?? item.OtherRequirement;
                item.ResumeRequirement  = command.ResumeRequirement ?? item.ResumeRequirement;
                item.ResumeApplyExpired = command.ResumeApplyExpired ?? item.ResumeApplyExpired;
                item.NumberOfJob        = command.NumberOfJob >= 0 ? command.NumberOfJob : item.NumberOfJob;
                item.ContactName        = command.ContactName ?? item.ContactName;
                item.ContactEmail       = command.ContactEmail ?? item.ContactEmail;
                item.ContactPhone       = command.ContactPhone ?? item.ContactPhone;
                item.ContactAdress      = command.ContactAdress ?? item.ContactAdress;


                await _repository.UpdateAsync(item);

                await _unitOfWork.Commit(cancellationToken);

                return(Result <int> .Success(item.Id));
            }
        }