Esempio n. 1
0
        public ActionResult Create(int?jobId)
        {
            Template jobTemplate = _templatesRepository.GetTemplateByJobId(jobId);

            if (jobTemplate == null)
            {
                return(NotFound());
            }
            if (!Convert.ToBoolean(jobTemplate.JobListing.IsActive))
            {
                return(RedirectToAction("Index"));
            }

            int userIdCurrentlyLoggedIn = Int32.Parse(User.Claims.FirstOrDefault(uc => uc.Type == ClaimTypes.NameIdentifier).Value);

            bool userAlreadyApplied = _applicationsRepository.UserAppliedAlready(userIdCurrentlyLoggedIn, jobId);

            if (userAlreadyApplied)
            {
                return(RedirectToAction("Index"));
            }

            ViewData["showWorkExperienceFields"] = jobTemplate.WorkExperience;
            ViewData["showSkillsFields"]         = jobTemplate.Skills;
            ViewData["showEducationFields"]      = jobTemplate.Education;
            ViewData["showOtherNotes"]           = jobTemplate.OtherNotes;

            ViewData["JobId"]   = jobId;
            ViewBag.SelectedNav = "Jobs";
            return(View());
        }
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            int userIdCurrentlyLoggedIn = Int32.Parse(User.Claims.FirstOrDefault(uc => uc.Type == ClaimTypes.NameIdentifier).Value);

            JobListing jobListing     = _jobListingsRepository.GetJobListingById(id);
            Template   templateFromDb = _templatesRepository.GetTemplateByJobId(id);

            bool isAllowedToSeeJobListing = _jobListingsRepository.isAllowedToModifyJobListing(userIdCurrentlyLoggedIn, jobListing.CompanyId);

            if (!isAllowedToSeeJobListing)
            {
                return(NotFound());
            }

            List <Company>  companiesAssignedToUserLoggedIn = _companiesRepository.GetCompaniesAssignedToUser(userIdCurrentlyLoggedIn);
            List <Category> categories = _categoriesRepository.GetCategories();

            List <string> regions = new List <string> {
                "Africa", "Asia", "The Caribbean", "Central America", "Europe", "Oceania", "North America", "South America"
            };
            List <string> types = new List <string> {
                "Full Time", "Part Time", "Remote", "Voluntary or carity acts"
            };

            EditJobListingWithTemplateViewModel editJobListingWithTemplateViewModel = new EditJobListingWithTemplateViewModel
            {
                Title          = jobListing.Title,
                Position       = jobListing.Position,
                Type           = jobListing.Type,
                Description    = jobListing.Description,
                Location       = jobListing.Location,
                JobListingId   = userIdCurrentlyLoggedIn,
                CategoryId     = jobListing.Category.CategoryId,
                CompanyId      = jobListing.Company.CompanyId,
                Region         = jobListing.Region,
                UserId         = jobListing.JobFinderUser.UserId,
                IsActive       = Convert.ToBoolean(jobListing.IsActive),
                Education      = Convert.ToBoolean(templateFromDb.Education),
                WorkExperience = Convert.ToBoolean(templateFromDb.WorkExperience),
                Skills         = Convert.ToBoolean(templateFromDb.Skills),
                OtherNotes     = Convert.ToBoolean(templateFromDb.OtherNotes)
            };

            ViewData["Companies"]  = new SelectList(companiesAssignedToUserLoggedIn, "CompanyId", "Name");
            ViewData["Categories"] = new SelectList(categories, "CategoryId", "Name");
            ViewData["Regions"]    = new SelectList(regions, regions);
            ViewData["Types"]      = new SelectList(types, types);
            ViewBag.SelectedNav    = "Dashboard";

            return(View(editJobListingWithTemplateViewModel));
        }