public IActionResult Join(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); Hangout hangout = dbContext.hangouts.FirstOrDefault(h => h.HangoutId == hangoutId); if (user.HangoutsAsParticipants.Any(h => h.HangoutId == hangoutId)) { Console.WriteLine("**********user is already participating*****"); return(RedirectToAction("Dashboard")); } HangoutParticipants newHangPart = new HangoutParticipants(); newHangPart.ParticipantId = user.UserId; newHangPart.HangoutId = hangoutId; dbContext.Add(newHangPart); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); }
public IActionResult Delete(int hangoutId) { if (FetchAuthorizedUser() == null) { return(RedirectToAction("Index")); } Hangout hangout = dbContext.hangouts.FirstOrDefault(h => h.HangoutId == hangoutId); dbContext.hangouts.Remove(hangout); dbContext.SaveChanges(); return(RedirectToAction("Dashboard")); }
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")); }
public IActionResult UpdateHangout(int id, [FromBody] Hangout hangout) { return(Ok()); }
public IActionResult CreateHangout(dynamic hangout) { var newHangout = new Hangout(hangout); return(Ok()); }