using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Text; namespace Sleis.ViewModels { public class ToggleRecord { public int RecordId { get; set; } public Dictionary UrlParams { get; set; } //public string ParamName { get; set; } //public object Value { get; set; } } public class ToggleInfo:ItemViewBase { public string LastFilteredValue { get; set; } public int[] FilteredIds{get;set;} public List Records { get; set; } public int NextId { get { //prevent location an index outside of the bounds of the array. Also, if MAX returned will hide next button on UI return (CurrentIndex < FilteredIds.Count() - 1) ? Records[CurrentIndex + 1].RecordId : Records.Count - 1; } } public int PreviousId { get { //prevent location an index outside of the bounds of the array. Also, if 0 will hide previous button on UI return (CurrentIndex - 1 >= 0) ? Records[CurrentIndex - 1].RecordId : CurrentIndex; //if at the beginning. Previous will redirect to current } } public int CurrentId { get; set; } public int CurrentIndex { get; set; } public ToggleRecord CurrentRecord { get { return Records[CurrentIndex]; } } public bool ShowNextButton() { return this.CurrentIndex < Records.Count() -1; } public bool ShowPrevButton() { return this.CurrentIndex > 0; } public ToggleInfo(int currentId, int[] filteredIds, string lastFilterValue, List records) { CurrentId = currentId; FilteredIds = filteredIds; LastFilteredValue = lastFilterValue; Records = records; CurrentIndex = Records.FindIndex(r => r.RecordId == currentId); //AdditionalUrlParams = new Dictionary>(); } /* public ToggleInfo(int currentId, int[] filteredIds, string lastFilterValue, Dictionary> additionalUrlParams) { AdditionalUrlParams = additionalUrlParams; CurrentId = currentId; FilteredIds = filteredIds; LastFilteredValue = lastFilterValue; } */ public void UpdateToggleInfo(int newCurrentIndex) { CurrentIndex = newCurrentIndex; } public string GetPreviousUrl() { return string.Format("{0}?reportId={1}&facilityId={2}&toggleIndex={3}{4}", PreviousId.ToString(), ReportId, FacilityId, CurrentIndex-1, AddAditionalParams(CurrentIndex-1)); } public string GetNextUrl() { return string.Format("{0}?reportId={1}&facilityId={2}&toggleIndex={3}{4}", NextId.ToString(), ReportId, FacilityId, CurrentIndex+1, AddAditionalParams(CurrentIndex + 1)); } private string AddAditionalParams(int recordIndex) { StringBuilder url = new StringBuilder(); if (recordIndex >= 0 && recordIndex < Records.Count && Records[recordIndex].UrlParams!=null) { foreach (string key in Records[recordIndex].UrlParams.Keys) { url.AppendFormat("&{0}={1}", key, Records[recordIndex].UrlParams[key].ToString()); } } return url.ToString(); } } }