//get PULAs based on filteres //GET: PULAs? public JsonResult GetFilteredSimplePULAs(string fDate, string eventID, string productID, string activeIngredientID) { string FormattedDate = "0"; DateTime? chosenDate = null; if (fDate != "0") { string unFormattedDate = fDate; int monthEnd = unFormattedDate.IndexOf(" "); if (monthEnd <= 0) monthEnd = unFormattedDate.IndexOf("+"); string month = unFormattedDate.Substring(0, monthEnd); string year = unFormattedDate.Substring(monthEnd + 1, 4); chosenDate = Convert.ToDateTime(month + "/01/" + year).AddMonths(1).AddDays(-1); FormattedDate = chosenDate.Value.ToShortDateString(); } BLTServiceCaller serviceCaller = BLTServiceCaller.Instance; var request = new RestRequest(); request.Resource = "PULAs/FilteredSimplePULAs?date={date}&aiID={activeIngredientID}&productID={productID}&eventID={eventID}"; request.RootElement = "ArrayOfPULA"; request.AddParameter("date", FormattedDate, ParameterType.UrlSegment); request.AddParameter("activeIngredientID", Convert.ToInt32(activeIngredientID), ParameterType.UrlSegment); request.AddParameter("productID", Convert.ToInt32(productID), ParameterType.UrlSegment); request.AddParameter("eventID", Convert.ToInt32(eventID), ParameterType.UrlSegment); PULAList PULAlist = serviceCaller.Execute<PULAList>(request); //send back CreatedList, PublishedList, EffectiveList PULAList PublishedList = new PULAList(); PULAList EffectiveList = new PULAList(); PULAList ExpiredList = new PULAList(); //published if (effective is null OR after chosenDate) AND (expired is null or after chosendate) PublishedList.PULA = PULAlist.PULA.Where(x => ((!x.Effective.HasValue) || (x.Effective.Value >= chosenDate)) && ((!x.Expired.HasValue) || (x.Expired.Value >= chosenDate))).ToList(); //effective if (effective is <= chosen date AND (expired is nll OR after chosenDate) EffectiveList.PULA = PULAlist.PULA.Where(x => ((x.Effective.Value <= chosenDate) && ((!x.Expired.HasValue) || (x.Expired.Value > chosenDate)))).ToList(); ExpiredList.PULA = PULAlist.PULA.Where(x => (x.Expired.HasValue && x.Expired.Value <= chosenDate)).ToList(); List<object> allOfThem = new List<object>(); allOfThem.Add(PublishedList.PULA); allOfThem.Add(EffectiveList.PULA); allOfThem.Add(ExpiredList.PULA); return Json(allOfThem, JsonRequestBehavior.AllowGet); }
//get PULAs based on EventID for contributor logged in //GET: PULas public JsonResult GetEventPULAs(string eventId) { BLTServiceCaller serviceCaller = BLTServiceCaller.Instance; var request = new RestRequest(); request.Resource = "/Events/{eventId}/PULAs"; request.RootElement = "ArrayOfPULA"; request.AddParameter("eventId", Convert.ToInt32(eventId), ParameterType.UrlSegment); PULAList PULAlist = serviceCaller.Execute<PULAList>(request); //send back CreatedList PULAList CreatedList = new PULAList(); CreatedList.PULA = PULAlist.PULA.Where(x => (x.Created <= DateTime.Now.Date && x.isPublished < 1) && x.Expired == null).ToList(); return Json(CreatedList.PULA, JsonRequestBehavior.AllowGet); }