/// <summary> /// This method is responsible for getting all the available jobs so the user can browse through them. /// If we want to show the jobs that the current user has created (if he is an employer) /// the method's only parameter is set to true and if we want to show all available jobs, it is set to false. /// </summary> /// <param name="viewCreatedJobs">view only created jobs</param> /// <returns>A new AllJobs view model for the jobs we have sellected based on the viewCreatedJobs parameter</returns> public AllJobsViewModel GetAllJobs(bool viewCreatedJobs) { var jobs = context.Jobs.Select(j => new CreateJobViewModel() { Id = j.Id, Name = j.Name, Employer = j.Employer, Salary = j.Salary, Category = j.Category, WorkPlace = j.WorkPlace, Applicants = j.Applicants }); if (viewCreatedJobs) { var loggedUser = userService.GetLoggedUser(); var employer = $"{loggedUser.FirstName} {loggedUser.LastName}"; jobs = jobs.Where(j => j.Employer == employer); } var model = new AllJobsViewModel() { Jobs = jobs }; return(model); }
public IActionResult Index(int page = 1, string searchString = null) { this.ViewData["CurrentFilter"] = searchString; if (!string.IsNullOrEmpty(searchString)) { var viewModel = new AllJobsViewModel { Jobs = this.jobsService.GetAll <JobsViewModel>().Where(x => x.Description.ToLower().Contains(searchString.ToLower()) || x.Title.ToLower().Contains(searchString.ToLower())), }; return(this.View(viewModel)); } var viewModel1 = new AllJobsViewModel { Jobs = this.jobsService.GetAll <JobsViewModel>(10, (page - 1) * 10), }; var count = this.jobsService.GetAll <JobsViewModel>().Count(); viewModel1.PagesCount = (int)Math.Ceiling((double)count / ItemsPerPage); if (viewModel1.PagesCount == 0) { viewModel1.PagesCount = 1; } viewModel1.CurrentPage = page; return(this.View(viewModel1)); }
public IActionResult JobsByCategory(int id) { var viewModel = new AllJobsViewModel { Jobs = this.jobsService.GetByCategoryId <JobsViewModel>(id), }; return(this.View("Index", viewModel)); }
public IActionResult All(int page = DefaultPageNumber) { var jobs = new AllJobsViewModel { Jobs = this.jobService.GetAll <SigleJobViewModel>(page, JobsCount), Page = page, JobsCount = this.jobService.JobsCount(), }; return(this.View(jobs)); }
public async Task <IActionResult> Index() { var user = await this.userManager.GetUserAsync(this.User); var viewModel = new AllJobsViewModel { Jobs = this.jobsService.GetById <JobsViewModel>(user.Id), }; return(this.View(viewModel)); }
public IActionResult Search(string keyWords, int page = DefaultPageNumber) { if (string.IsNullOrWhiteSpace(keyWords)) { return(this.RedirectToAction(nameof(this.All))); } this.TempData["keyWords"] = keyWords; var jobs = new AllJobsViewModel { Jobs = this.jobService.SearchResults <SigleJobViewModel>(page, JobsCount, keyWords), Page = page, JobsCount = this.jobService.SearchCount(), }; return(this.View(jobs)); }