Ejemplo n.º 1
0
        public async Task <IActionResult> AddApplications(int id, AddApplicationsInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View("AddAplications"));
            }

            ClaimsPrincipal userIdentity         = this.User;
            List <int>      schoolApplicationIds = new List <int>();

            //TODO Refactor Scalability
            #region refactorWithServiceModel
            //candidate.SchoolCandidates.Add(
            //    new SchoolCandidateServiceModel
            //    {
            //        CandidateId = id,
            //        SchoolId = firstWishSchoolId,
            //    });
            #endregion
            //First wish
            if (input.FirstWishSchool != null)
            {
                int firstWishSchoolId = await this.schoolsService
                                        .GetSchoolIdByName(input.FirstWishSchool);

                if (!schoolApplicationIds.Contains(firstWishSchoolId))
                {
                    schoolApplicationIds.Add(firstWishSchoolId);
                }
            }

            //Second wish
            if (input.SecondWishSchool != null)
            {
                int secondWishSchoolId = await this.schoolsService
                                         .GetSchoolIdByName(input.SecondWishSchool);

                if (!schoolApplicationIds.Contains(secondWishSchoolId))
                {
                    schoolApplicationIds.Add(secondWishSchoolId);
                }
            }

            //Third wish
            if (input.ThirdWishSchool != null)
            {
                int thirdWishSchoolId = await this.schoolsService
                                        .GetSchoolIdByName(input.ThirdWishSchool);

                if (!schoolApplicationIds.Contains(thirdWishSchoolId))
                {
                    schoolApplicationIds.Add(thirdWishSchoolId);
                }
            }

            await this.candidatesService.AddApplications(id, schoolApplicationIds);

            return(this.Redirect($"/Users/Candidate/Profile/{id}"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> AddApplications(int id)
        {
            CandidateServiceModel candidate = await this.candidatesService.GetCandidateById(id);

            if (candidate == null || candidate.User.UserName != this.User.Identity.Name)
            {
                return(this.View("_AccessDenied"));
            }

            IQueryable <SchoolServiceModel> allSchools = null;

            if (candidate.MotherId == 1 || candidate.MotherId == 2 ||
                candidate.FatherId == 1 || candidate.FatherId == 2)
            {
                allSchools = this.schoolsService
                             .GetAllSchools();
            }
            else
            {
                allSchools = this.schoolsService
                             .GetAllSchools()
                             .Where(x => x.District.Id == candidate.Mother.Address.PermanentDistrictId ||
                                    x.District.Id == candidate.Mother.Address.CurrentDistrictId ||
                                    x.District.Id == candidate.Father.Address.PermanentDistrictId ||
                                    x.District.Id == candidate.Father.Address.CurrentDistrictId ||
                                    x.District.Id == candidate.Mother.WorkDistrictId ||
                                    x.District.Id == candidate.Father.WorkDistrictId);
            }

            this.ViewData["AllSchools"] = allSchools
                                          .Select(p => new AddSchoolApplicationsViewModel {
                Id = p.Id, Name = p.Name, DistrictName = p.District.Name
            })
                                          .ToList();

            AddApplicationsInputModel model = new AddApplicationsInputModel();

            model.CandidateId   = candidate.Id;
            model.CandidateName = candidate.FullName;
            return(this.View("AddApplications", model));
        }