public ViewResult ViewEvents() { if (HttpContext.User.Identity.IsAuthenticated) { return(this.View(nameof(Index), "Home")); } var categories = this.events.GetAll() .Where(e => e.IsApproved) .Select(e => e.Category) .Distinct() .ToList(); Dictionary <string, bool> dict = new Dictionary <string, bool>(); foreach (var i in categories) { dict.Add(i, true); } var model = new FilterEventsModel() { Events = this.events.GetAll() .Where(e => e.IsApproved) .OrderBy(e => e.DateTime).ToList(), Categories = dict }; return(this.View(model)); }
private ViewResult ViewEvents( string categories, DateTime?start, DateTime?end) { var result = new List <Event>(); var categoriesArray = categories.Split(','); foreach (string category in categoriesArray) { var currentEvents = this.events.GetAll() .Where(e => e.IsApproved) .Where(e => e.Category == category) .Where(e => (start == null || DateTime.Compare(e.DateTime, start.Value) >= 0) && (end == null || DateTime.Compare(e.DateTime, end.Value) <= 0)) .ToList(); result.AddRange(currentEvents); } var categoriesAll = this.events.GetAll() .Where(e => e.IsApproved) .Select(e => e.Category) .Distinct() .ToList(); Dictionary <string, bool> dict = new Dictionary <string, bool>(); foreach (var i in categoriesAll) { dict.Add(i, categoriesArray.Contains(i)); } var model = new FilterEventsModel() { Events = result, Categories = dict }; return(this.View(nameof(this.ViewEvents), model)); }