public IActionResult Dashboard() { if (FetchAuthorizedUser() == null) { return(RedirectToAction("Index")); } User user = FetchAuthorizedUser(); List <Hangout> hangouts = dbContext.hangouts.Include(h => h.Creator).Include(h => h.HangoutParticipants).ThenInclude(h => h.Participant).OrderBy(h => h.Date).ToList(); List <Hangout> pastHangouts = hangouts.Where(h => Convert.ToDateTime(h.Date).Subtract(DateTime.Now).TotalDays < 0 && Convert.ToDateTime(h.Time).Subtract(DateTime.Now).TotalMinutes < 0).ToList(); if (pastHangouts.Count > 0) { foreach (var pastHang in pastHangouts) { Console.WriteLine("***************"); Console.WriteLine(pastHang.Date); } } hangouts = hangouts.Except(pastHangouts).ToList(); HangoutUserViewModel modelData = new HangoutUserViewModel(); modelData.User = user; modelData.Hangouts = hangouts; return(View("Dashboard", modelData)); }
public IActionResult Show(int hangoutId) { if (FetchAuthorizedUser() == null) { return(RedirectToAction("Index")); } User user = FetchAuthorizedUser(); Hangout hangout = dbContext.hangouts.Include(h => h.Creator).Include(h => h.HangoutParticipants).ThenInclude(h => h.Participant).FirstOrDefault(h => h.HangoutId == hangoutId); HangoutUserViewModel modelData = new HangoutUserViewModel(); modelData.Hangout = hangout; modelData.User = user; return(View("Show", modelData)); }
public IActionResult CreateHangout(HangoutUserViewModel formData) { if (FetchAuthorizedUser() == null) { return(RedirectToAction("Index")); } User user = FetchAuthorizedUser(); Hangout hangout = formData.Hangout; if (ModelState.IsValid) { hangout.CreatorId = user.UserId; dbContext.Add(hangout); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); } return(View("New")); }