public ActionResult Update(Jop jop) { if (!ModelState.IsValid) { var viewModel = new JopFormsViewModel { jop = jop, Locations = db.Locations.ToList(), Careers = db.Careers.ToList(), Experiences = db.Experiences.ToList() }; return(View("EditJop", viewModel)); } var jopInForm = db.Jops.Single(j => j.Id == jop.Id); jopInForm.Title = jop.Title; jopInForm.CompanyName = jop.CompanyName; jopInForm.Email = jop.Email; jopInForm.Watsapp = jop.Watsapp; jopInForm.Salary = jop.Salary; jopInForm.CareerId = jop.CareerId; jopInForm.LocationId = jop.LocationId; jopInForm.ExperienceId = jop.ExperienceId; jopInForm.JopType = jop.JopType; jopInForm.Details = jop.Details; jopInForm.LastUpdated = DateTime.Now; db.SaveChanges(); return(RedirectToAction("JopIn", "Home")); }
public ActionResult EditJop(int?id) { if (id == null) { return(HttpNotFound()); } var editJop = db.Jops.SingleOrDefault(j => j.Id == id); if (editJop == null) { return(HttpNotFound()); } var viewModel = new JopFormsViewModel { jop = editJop, Locations = db.Locations.ToList(), Careers = db.Careers.ToList(), Experiences = db.Experiences.ToList() }; return(View(viewModel)); }
public ActionResult JopIn(int?page, int?location, int?career, int?experience, string jopType, string datePosted, string serach, string reset) { var allJops = db.Jops.Include(j => j.Location).Include(j => j.Career).OrderByDescending(j => j.AnnouncedDate).ToList(); // reset the filtering if (reset == "true") { TempData.Clear(); } // filter by location if (location != null) { if (TempData.ContainsKey("location")) { TempData["location"] = location; } else { TempData.Add("location", location); } } if (TempData["location"] != null) { TempData.Keep("location"); ViewBag.location = TempData["location"]; var stringLocation = db.Locations.Find(ViewBag.location); ViewBag.stringLocation = stringLocation.Name; allJops = allJops.Where(j => j.LocationId == ViewBag.location).ToList(); } // filter by career if (career != null) { if (TempData.ContainsKey("career")) { TempData["career"] = career; } else { TempData.Add("career", career); } } if (TempData["career"] != null) { TempData.Keep("career"); ViewBag.career = TempData["career"]; var stringCareer = db.Careers.Find(ViewBag.career); ViewBag.stringCareer = stringCareer.Name; allJops = allJops.Where(j => j.CareerId == ViewBag.career).ToList(); } ////filter by experience if (experience != null) { if (TempData.ContainsKey("experience")) { TempData["experience"] = experience; } else { TempData.Add("experience", experience); } } if (TempData["experience"] != null) { TempData.Keep("experience"); ViewBag.experience = TempData["experience"]; var stringExperience = db.Experiences.Find(ViewBag.experience); ViewBag.stringExperience = stringExperience.TotalName; allJops = allJops.Where(j => j.ExperienceId == ViewBag.experience).ToList(); } ////filter by JopType if (!string.IsNullOrEmpty(jopType)) { if (TempData.ContainsKey("jopType")) { TempData["jopType"] = jopType; } else { TempData.Add("jopType", jopType); } } if (TempData["jopType"] != null) { TempData.Keep("jopType"); ViewBag.jopType = TempData["jopType"]; allJops = allJops.Where(j => j.JopType == ViewBag.jopType).ToList(); } ////filter by datePosted DateTime searchDate = DateTime.Now; if (!string.IsNullOrEmpty(datePosted)) { if (datePosted == "Last 24 Hours") { searchDate = DateTime.Now.AddDays(-1); } else if (datePosted == "One Week") { searchDate = DateTime.Now.AddDays(-7); } else if (datePosted == "One Month") { searchDate = DateTime.Now.AddDays(-30); } else if (datePosted == "All") { searchDate = DateTime.Now.AddYears(-200); } if (TempData.ContainsKey("searchDate")) { TempData["searchDate"] = searchDate; } else { TempData.Add("searchDate", searchDate); } if (TempData.ContainsKey("datePosted")) { TempData["datePosted"] = datePosted; } else { TempData.Add("datePosted", datePosted); } } if (TempData["searchDate"] != null) { TempData.Keep("searchDate"); ViewBag.searchDate = TempData["searchDate"]; TempData.Keep("datePosted"); ViewBag.datePosted = TempData["datePosted"]; allJops = allJops.Where(j => j.AnnouncedDate >= ViewBag.searchDate).ToList(); } ////filter by search if (!string.IsNullOrEmpty(serach)) { if (TempData.ContainsKey("serach")) { TempData["serach"] = serach; } else { TempData.Add("serach", serach); } } if (TempData["serach"] != null) { TempData.Keep("serach"); ViewBag.serach = TempData["serach"]; allJops = allJops.Where(j => j.Title.Contains(ViewBag.serach) || j.CompanyName.Contains(ViewBag.serach) || j.Details.Contains(ViewBag.serach)).ToList(); } ViewBag.JopsCount = allJops.Count(); byte pageSize = 6; int pageNumber = (page ?? 1); var viewModel = new JopFormsViewModel { Jops = allJops.ToPagedList(pageNumber, pageSize), jop = new Jop(), Careers = db.Careers.ToList(), Locations = db.Locations.ToList(), Experiences = db.Experiences.ToList() }; if (TempData.ContainsKey("shortMessage")) { ViewBag.Message = TempData["shortMessage"].ToString(); return(View(viewModel)); } else { return(View(viewModel)); } }