public ActionResult Post([FromForm] string key, [FromForm] string comment, [FromForm] string password, [FromForm] string cookieFailKey = null) { var keyInfo = new CookieFailKeyInfo(cookieFailKey); List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); var item = list.FirstOrDefault(a => a.Id == key); if (item == null) { return(NotFound()); } var assignment = AssignmentDetailHelper.GetAssignmentDetail(HttpContext, keyInfo, _appSettings, item); if (assignment == null) { return(NotFound()); } string sessionKey = ""; if (keyInfo.IsVaild) { sessionKey = keyInfo.Key; var tmpUrl = keyInfo.AvailableAssignmentsUrl; } else { byte[] cookieData; if (HttpContext.Session.TryGetValue("Session-Cookie", out cookieData)) { sessionKey = System.Text.Encoding.UTF8.GetString(cookieData); } else { return(this.Unauthorized()); } } var cookieContainer = new CookieContainer(); cookieContainer.Add(new System.Uri("http://volontar.polisen.se/"), new Cookie("PHPSESSID", sessionKey)); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) { AssignmentDetailHelper.SubmitInterestOfAssignment(handler, assignment, comment, password); return(this.Ok()); } }
//[ResponseCache(VaryByQueryKeys = new[] { "key" }, Duration = 60)] public JsonResult Get(string key, string cookieFailKey = null) { try { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); var item = list.FirstOrDefault(a => a.Id == key); if (item == null) { return(Json(null)); } var assignment = AssignmentDetailHelper.GetAssignmentDetail(HttpContext, keyInfo, _appSettings, item); if (assignment == null) { return(Json(null)); } return(Json(new AssignmentDetail { Id = item.Id, Name = item.Name, Category = item.Category, Date = item.Date, Area = item.Area, Description = assignment.Description, Time = assignment.Time, ContactInfo = assignment.ContactInfo, MeetupTime = assignment.MeetupTime, MeetupPlace = assignment.MeetupPlace, LastRequestDate = assignment.LastRequestDate, GoogleCalendarEventUrl = assignment.GoogleCalendarEventUrl, WantedNumberOfPeople = assignment.WantedNumberOfPeople, CurrentNumberOfPeople = assignment.CurrentNumberOfPeople, InterestsFormUrl = assignment.InterestsFormUrl, InterestsValues = assignment.InterestsValues })); } catch (System.Exception ex) { return(Json(new Assignment { Name = ex.Message })); } }
public bool Get([FromQuery] string cookieFailKey) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); try { var keyInfo = new CookieFailKeyInfo(cookieFailKey); var list = AvailableAssignmentsHelper.GetAvailableAssignments(HttpContext, keyInfo); return(list.Count > 0); } catch (System.Exception) { return(false); } }
public int Get(string cookieFailKey = null) { this.Response.Headers.Add("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); try { var keyInfo = new CookieFailKeyInfo(cookieFailKey); var list = AvailableAssignmentsHelper.GetAvailableAssignments(HttpContext, keyInfo); if (list.Count == 0) { return(1); } else { return(2); } } catch (System.Exception) { return(-2); } }
//[ResponseCache(VaryByHeader = "Cookie", VaryByQueryKeys = new[] { "key" }, Duration = 60)] public AvailableAssignmentsResult Get(string key, int startIndex = 0, int nOfItems = -1, string filterAlwaysShowTypes = null, string filterNeverShowTypes = null, string filterHideWorkDayTypes = null, string filterHideWeekendTypes = null, string filterNeverShowAreas = null, string filterAlwaysShowAreas = null, string filterNeverShowSpecTypes = null, string cookieFailKey = null) { // Spara svaret i 5 minuter (detta gör att sidor laddar snabbare när vi går tillbaka från att se detaljer för ett uppdrag) this.Response.Headers.Add("Cache-Control", "max-age=300"); var keyInfo = new CookieFailKeyInfo(cookieFailKey); var totalNofItems = 0; // TODO: 1. Sanity checking // TODO: 2. Validate login List <Assignment> list = AvailableAssignmentsHelper.GetAvailableAssignments(this.HttpContext, keyInfo); totalNofItems = list.Count; // filter items var filterNofItems = 0; var filterSettings = AvailableAssignmentsHelper.GetFilterSettings(filterAlwaysShowTypes, filterNeverShowTypes, filterHideWorkDayTypes, filterHideWeekendTypes, filterNeverShowAreas, filterAlwaysShowAreas, filterNeverShowSpecTypes ); list = AvailableAssignmentsHelper.FilerItems(list, filterSettings, HttpContext, _appSettings); filterNofItems = list.Count; // only get ONE item, if available if (key != null) { list = list.Where(a => a.Id == key).ToList(); } // support paging, start position if (startIndex > 0) { list = list.Skip(startIndex).ToList(); } int skipCount; list = AvailableAssignmentsHelper.AdvancedFilerItems(list, filterSettings, HttpContext, keyInfo, _appSettings, out skipCount); // support paging, number of items if (nOfItems > 0) { list = list.Take(nOfItems).ToList(); } // 3. Return available assignmets var groupedList = list.GroupBy(AvailableAssignmentsHelper.GroupByDay); var nextStartIndex = 0; if (skipCount > 0 && list.Count > 0) { nextStartIndex = skipCount + startIndex; } return(new AvailableAssignmentsResult { NextStartIndex = nextStartIndex, TotalNumberOfItems = totalNofItems, FilteredNofItems = filterNofItems, Items = groupedList.ToArray() }); }