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());
            }
        }
Пример #2
0
        //[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
                }));
            }
        }