コード例 #1
0
        public async Task <IActionResult> OnPostCreateAsync()
        {
            JobCertificates = await _jobCompetencyService.GetJobCertificates();

            JobCompetenciesKnowledge = await _jobCompetencyService.GetJobCompetenciesByTypeId(1);

            JobCompetenciesTechnical = await _jobCompetencyService.GetJobCompetenciesByTypeId(2);

            JobCompetenciesBehavioural = await _jobCompetencyService.GetJobCompetenciesByTypeId(3);

            JobCompetenciesExecutive = await _jobCompetencyService.GetJobCompetenciesByTypeId(4);

            CurrentSelectedJobGroup = await _jobCompetencyService.GetJobGroupById(JobGroupId);

            JobGroupPositions = await _jobCompetencyService.GetSubGroupLevelsByGroupId(JobGroupId);

            JobGroups = await _jobCompetencyService.GetJobGroups();

            JobCertificateDescriptions = await _jobCompetencyService.GetAllJobCertificateDescriptions();

            LevelCode = LevelValue.Split("/")[2];
            RegionIds = string.Empty;
            foreach (var id in SelectedRegionIds)
            {
                RegionIds += id + "-";
            }
            foreach (var cid in AddedCertificateIds.Split("-"))
            {
                if (!string.IsNullOrEmpty(cid))
                {
                    var cidInt         = int.Parse(cid.Split("&")[0]);
                    var certificateDto = await _jobCompetencyService.GetJobCertificateById(cidInt);

                    certificateDto.CertificateDescId = int.Parse(cid.Split("&")[1]);
                    AddedCertificates.Add(certificateDto);
                }
            }
            foreach (var cid in AddedKnowledgeCompetencyIds.Split("-"))
            {
                if (!string.IsNullOrEmpty(cid))
                {
                    var cidc   = cid.Split("&")[0];
                    var clevel = cid.Split("&")[1];

                    if (!string.IsNullOrEmpty(cidc) && !string.IsNullOrEmpty(clevel))
                    {
                        var cidInt     = int.Parse(cidc);
                        var cLevel     = int.Parse(clevel);
                        var competency = await _jobCompetencyService.GetJobCompetencyLevelByIdLevelId(cidInt, cLevel);

                        AddedKnowledgeCompetencies.Add(competency);
                    }
                }
            }
            foreach (var cid in AddedTechnicalCompetencyIds.Split("-"))
            {
                if (!string.IsNullOrEmpty(cid))
                {
                    var cidc   = cid.Split("&")[0];
                    var clevel = cid.Split("&")[1];

                    if (!string.IsNullOrEmpty(cidc) && !string.IsNullOrEmpty(clevel))
                    {
                        var cidInt     = int.Parse(cidc);
                        var cLevel     = int.Parse(clevel);
                        var competency = await _jobCompetencyService.GetJobCompetencyLevelByIdLevelId(cidInt, cLevel);

                        AddedTechnicalCompetencies.Add(competency);
                    }
                }
            }
            foreach (var cid in AddedBehaviouralCompetencyIds.Split("-"))
            {
                if (!string.IsNullOrEmpty(cid))
                {
                    var cidc   = cid.Split("&")[0];
                    var clevel = cid.Split("&")[1];

                    if (!string.IsNullOrEmpty(cidc) && !string.IsNullOrEmpty(clevel))
                    {
                        var cidInt     = int.Parse(cidc);
                        var cLevel     = int.Parse(clevel);
                        var competency = await _jobCompetencyService.GetJobCompetencyLevelByIdLevelId(cidInt, cLevel);

                        AddedBehaviouralCompetencies.Add(competency);
                    }
                }
            }
            foreach (var cid in AddedExecutiveCompetencyIds.Split("-"))
            {
                if (!string.IsNullOrEmpty(cid))
                {
                    var cidc   = cid.Split("&")[0];
                    var clevel = cid.Split("&")[1];

                    if (!string.IsNullOrEmpty(cidc) && !string.IsNullOrEmpty(clevel))
                    {
                        var cidInt     = int.Parse(cidc);
                        var cLevel     = int.Parse(clevel);
                        var competency = await _jobCompetencyService.GetJobCompetencyLevelByIdLevelId(cidInt, cLevel);

                        AddedExecutiveCompetencies.Add(competency);
                    }
                }
            }
            var jobPositionId = _jobCompetencyService.GetJobPositionIdByTitle(Request.Form["titleEng"]).Result;

            if (jobPositionId == 0)
            {
                jobPositionId = await _jobCompetencyService.PostJobPositionGetId(Request.Form["titleEng"], Request.Form["titleFre"]);

                var jobGroupPosition = new JobGroupPosition()
                {
                    JobGroupId      = JobGroupId,
                    JobPositionId   = jobPositionId,
                    SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                    JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                };
                _jobCompetencyService.PostJobGroupPosition(jobGroupPosition);
                foreach (var competency in AddedKnowledgeCompetencies)
                {
                    var jobrolepositioncompetency = new JobRolePositionCompetencyRating()
                    {
                        JobPositionId = jobPositionId,
                        CompetencyId  = competency.CompetencyId,
                        CompetencyLevelRequirementId = competency.CompetencyLevelRequirementId,
                        CompetencyTypeId             = 1,
                        CompetencyRatingLevelId      = competency.CompetencyRatingLevelId,
                        SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                        JobGroupId      = JobGroupId
                    };
                    _jobCompetencyService.PostJobRolePositionCompetency(jobrolepositioncompetency);
                }
                foreach (var competency in AddedTechnicalCompetencies)
                {
                    var jobrolepositioncompetency = new JobRolePositionCompetencyRating()
                    {
                        JobPositionId = jobPositionId,

                        CompetencyId = competency.CompetencyId,
                        CompetencyLevelRequirementId = competency.CompetencyLevelRequirementId,
                        CompetencyTypeId             = 2,
                        CompetencyRatingLevelId      = competency.CompetencyRatingLevelId,
                        SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                        JobGroupId      = JobGroupId
                    };

                    _jobCompetencyService.PostJobRolePositionCompetency(jobrolepositioncompetency);
                }
                foreach (var competency in AddedBehaviouralCompetencies)
                {
                    var jobrolepositioncompetency = new JobRolePositionCompetencyRating()
                    {
                        JobPositionId = jobPositionId,
                        CompetencyId  = competency.CompetencyId,
                        CompetencyLevelRequirementId = competency.CompetencyLevelRequirementId,
                        CompetencyTypeId             = 3,
                        CompetencyRatingLevelId      = competency.CompetencyRatingLevelId,
                        SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                        JobGroupId      = JobGroupId
                    };

                    _jobCompetencyService.PostJobRolePositionCompetency(jobrolepositioncompetency);
                }
                foreach (var competency in AddedExecutiveCompetencies)
                {
                    var jobrolepositioncompetency = new JobRolePositionCompetencyRating()
                    {
                        JobPositionId = jobPositionId,
                        CompetencyId  = competency.CompetencyId,
                        CompetencyLevelRequirementId = competency.CompetencyLevelRequirementId,
                        CompetencyTypeId             = 4,
                        CompetencyRatingLevelId      = competency.CompetencyRatingLevelId,
                        SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                        JobGroupId      = JobGroupId
                    };

                    _jobCompetencyService.PostJobRolePositionCompetency(jobrolepositioncompetency);
                }
                foreach (var id in SelectedRegionIds)
                {
                    var jobrolepositionlocation = new JobRolePositionLocation()
                    {
                        JobLocationRegionId = int.Parse(id),
                        JobGroupId          = JobGroupId,
                        JobPositionId       = jobPositionId,
                        SubJobGroupId       = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId     = int.Parse(LevelValue.Split("/")[1])
                    };
                    _jobCompetencyService.PostJobRolePositionLocation(jobrolepositionlocation);
                }

                var jobrolepositionhlcategory = new JobRolePositionHLCategory()
                {
                    JobGroupId      = JobGroupId,
                    JobPositionId   = jobPositionId,
                    SubJobGroupId   = int.Parse(LevelValue.Split("/")[0]),
                    JobGroupLevelId = int.Parse(LevelValue.Split("/")[1]),
                    JobHLCategoryId = int.Parse(JobHLCategory)
                };
                _jobCompetencyService.PostJobRolePositionHLCategory(jobrolepositionhlcategory);
                foreach (var certificate in AddedCertificates)
                {
                    var jobrolepositioncertificate = new JobRolePositionCertificate()
                    {
                        JobPositionId            = jobPositionId,
                        JobGroupId               = JobGroupId,
                        SubJobGroupId            = int.Parse(LevelValue.Split("/")[0]),
                        JobGroupLevelId          = int.Parse(LevelValue.Split("/")[1]),
                        CertificateDescriptionId = certificate.CertificateDescId,
                        CertificateId            = certificate.Id,
                    };
                    _jobCompetencyService.PostJobRolePositionCertificate(jobrolepositioncertificate);
                }
            }
            else
            {
                return(Page());
            }

            /*
             * if (!ModelState.IsValid)
             * {
             *  return Page();
             * }
             *
             * _context.Competencies.Add(Competency);
             * await _context.SaveChangesAsync();
             */
            // string parameters = $"nameEng={Competency.NameEng}&nameFre={Competency.NameFre}&descEng={Competency.DescEng}&descFre={Competency.DescFre}";
            // try
            // {
            // _jobCompetencyService.PostJobCompetency(Competency);
            // }
            // catch(Exception ex) {
            return(RedirectToPage("Index"));
            //   }
            //return Page();
        }