public HttpResponseMessage GetJobDetails(int id) { JobPostViewModel job = null; try { job = JobsCacheManager.ListJobPosts.Find(j => j.id == id); if (job == null) { // get it from database var jobPost = db.JobPosts.Where(j => !(j.IsDeleted ?? false) && j.Id == id).SingleOrDefault(); if (jobPost != null) job = new JobPostViewModel(jobPost); } } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.InternalServerError, ex); } if (job == null) return Request.CreateResponse(HttpStatusCode.NotFound); else if(job.expiresOn.HasValue && job.expiresOn.Value < DateTime.UtcNow) return Request.CreateResponse(HttpStatusCode.Gone); return Request.CreateResponse<JobPostViewModel>(HttpStatusCode.OK, job); }
public HttpResponseMessage PostJob(JobPostViewModel item) { var modelStateErrors = ModelState.Values.ToList(); List<string> errors = new List<string>(); foreach (var s in modelStateErrors) foreach (var e in s.Errors) if (e.ErrorMessage != null && e.ErrorMessage.Trim() != "") errors.Add(e.ErrorMessage); if (errors.Count == 0) { try { var entity = item.ToEntity(); if (User.Identity.IsAuthenticated) { var currentUser = UserManager.FindByName(User.Identity.Name); entity.Owner = currentUser; // make sure any anonymous posts are associated to the user CheckForAnonymousActions(); entity.CreatedBy = currentUser.Id; } else entity.CreatedBy = Guid.NewGuid().ToString(); db.JobPosts.Add(entity); db.SaveChanges(); return Request.CreateResponse(HttpStatusCode.Created, entity); } catch { return Request.CreateResponse(HttpStatusCode.InternalServerError); } } else { return Request.CreateResponse<List<string>>(HttpStatusCode.BadRequest, errors); } }
// GET: Main public ActionResult Index() { string escaped_fragment = Request.QueryString["_escaped_fragment_"]; ViewBag.Title = "AngJobs | AngularJs jobs for web developers"; if (escaped_fragment == null) { //add meta for gbot //<meta name="fragment" content="!"> ViewBag.ShowFragmentMeta = true; return View(); } else { var db = Request.GetOwinContext().Get<DBContext>(); var jobdetails = "jobdetails"; var daily = "daily"; var daily_day = "day"; var jobs = "jobs"; var home = "home"; var inbox = "inbox"; var about = "about"; const string permanent = "permanent"; const string fulltime = "full-time"; var googlebotView = "~/Views/GoogleBot/Index.cshtml"; var pDetailsIndex = escaped_fragment.IndexOf(jobdetails, StringComparison.InvariantCultureIgnoreCase); var pJobsIndex = escaped_fragment.IndexOf(jobs + "/", StringComparison.InvariantCultureIgnoreCase); var pDailyIndex = escaped_fragment.IndexOf(daily, StringComparison.InvariantCultureIgnoreCase); var pAboutIndex = escaped_fragment.IndexOf(about, StringComparison.InvariantCultureIgnoreCase); if (pDetailsIndex > 0) { var jobId = int.Parse(escaped_fragment.Substring(pDetailsIndex + 1 + jobdetails.Length)); var jobPost = db.JobPosts.Find(jobId); if(jobPost == null || (jobPost.IsDeleted ?? false)) throw new HttpException(404, "Job not found"); var data = new JobPostViewModel(jobPost); var pageTitle = data.jobTitle + " - AngularJs job"; return View(googlebotView, new GoogleBotPage { page = jobdetails, data = data, pageTitle = pageTitle }); } else if (pDailyIndex > 0) { //checked if any params DateTime day = DateTime.Today; var thisPage = daily; object thisData = JobsCacheManager.ListDailyJobPostsShortDescription; int jIndex = pDailyIndex + 1 + daily.Length; if (jIndex < escaped_fragment.Length && DateTime.TryParse(escaped_fragment.Substring(jIndex), out day)) { thisPage = daily_day; thisData = new { day = day, list = (thisData as OrderedDictionary)[day]}.ToExpando(); } return View(googlebotView, new GoogleBotPage { page = thisPage, data = thisData }); } else if (pAboutIndex > 0) { return View(googlebotView, new GoogleBotPage { page = about, data = null }); } string jobType = pJobsIndex > 0 ? escaped_fragment.Substring(pJobsIndex + 1 + jobs.Length) : string.Empty; if (!string.IsNullOrEmpty(jobType) && jobType != inbox ) { switch (jobType) { case permanent: return GetBotPage(db, googlebotView, home, jobType, fulltime); case fulltime: return GetBotPage(db, googlebotView, home, jobType, permanent); default: return View(googlebotView, new GoogleBotPage { page = home, data = JobsCacheManager.ListJobPostsShortDescription}); } } else { return View(googlebotView, new GoogleBotPage { page = home, data = JobsCacheManager.ListJobPostsShortDescription}); } } }