/// <summary>
        /// Contains the logic for prosessing and returning the Timeline Register and its sorting.
        /// </summary>
        /// <param name="sortOrder">String of perticular order of sort</param>
        /// <param name="searchString">String for perticular search from user</param>
        /// <param name="page">Int containg the paged number</param>
        /// <returns>View</returns>
        public IActionResult Timelines(string sortOrder, string searchString, int?page)
        {
            //Setting Viewdata
            ViewData["NameSortParm"]  = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "name";
            ViewData["DateSortParm"]  = sortOrder == "Date" ? "date_desc" : "Date";
            ViewData["CurrentFilter"] = searchString;

            //Attempting to get the timelines to be displayed
            TimelineListViewModel model = new TimelineListViewModel();

            try
            {
                model = GetAllTimelines(model);
            }
            catch
            {
                return(RedirectToAction("APIError"));
            }


            //Sets to var and determins if there is a search to take place
            //If there is a search then limit the results to the searched paramiters
            var results = from s in model.Timelines
                          select s;

            if (!String.IsNullOrEmpty(searchString))
            {
                results = results.Where(s => s.Title.ToLower().Contains(searchString.ToLower()) ||
                                        (s.GetDateTime().ToString()).Contains(searchString));
            }

            //Switch for sorting the data in perticular order by user determined
            switch (sortOrder)
            {
            case "name_desc":
                results = results.OrderByDescending(s => s.Title);
                break;

            case "Date":
                results = results.OrderBy(s => s.CreationTimeStamp);
                break;

            case "name":
                results = results.OrderBy(s => s.Title);
                break;

            default:
                results = results.OrderByDescending(s => s.CreationTimeStamp);
                break;
            }


            //Variable set up for return to view
            var pagenumber = page ?? 1;
            var onepage    = results.ToPagedList(pagenumber, 10);

            ViewBag.OnePageOfProducts = onepage;

            return(View());
        }
Beispiel #2
0
        /// <summary>
        /// Gets the TimelineId of the timeline for an Event
        /// </summary>
        /// <param name="Id">String Id of Event</param>
        /// <returns>String Id of the found timeline</returns>
        protected string GetTimelineID(string Id)
        {
            TimelineListViewModel resultsDTO = new TimelineListViewModel(); //Model set and populate with data

            resultsDTO = GetSystemData();

            Timeline timeline = new Timeline();

            timeline = resultsDTO.Timelines.Find(x => x.TimelineEvents.Exists(y => y.Id == Id)); //search for timeline with eventId contained in

            return(timeline.Id);                                                                 //return id
        }
        /// <summary>
        /// Makes a request to the API and returns a populated view model with all Timelines
        /// </summary>
        /// <param name="model">TimelineListViewModel viewmodel to be populated with a list of Timelines</param>
        /// <returns>Populated TimelineListViewModel viewmodel</returns>
        private TimelineListViewModel GetAllTimelines(TimelineListViewModel model)
        {
            var           request  = new RestRequest("Timeline/GetTimelines");                   //setting up the request params
            IRestResponse response = GetRequest(request);                                        //Uses IdeagenAPI wrapperclass to make a request and retreives the response

            var resultsDTO = JsonConvert.DeserializeObject <List <Timeline> >(response.Content); //Deserializes the results from the response

            //Populates the viewmodel with relevent results
            foreach (Timeline x in resultsDTO)
            {
                model.Timelines.Add(x);
            }

            return(model);
        }
Beispiel #4
0
        /// <summary>
        /// Gets events from the system data for the Timeline with specified Id
        /// </summary>
        /// <param name="Id">string Id of timeline for event to be retreived</param>
        /// <returns></returns>
        private EventListViewModel GetEvents(string Id)
        {
            EventListViewModel    model      = new EventListViewModel(); //set models
            TimelineListViewModel resultsDTO = new TimelineListViewModel();

            resultsDTO = GetSystemData(); //Gets entire system data

            if (resultsDTO == null)       //Error check
            {
                model = null;
                return(model);
            }

            List <Event> EventsList = new List <Event>();

            foreach (Timeline x in resultsDTO.Timelines.Where(x => x.Id.Equals(Id)))
            {
                model.Events = x.TimelineEvents; //Inserts events into model
            }

            model.Events = model.Events.OrderBy(o => o.EventDateTime).ToList();

            return(model);
        }