Esempio n. 1
0
 public IActionResult CreateEvent(Event eventSubmission)
 {
     if (ModelState.IsValid)
     {
         if (DateTime.Now.CompareTo(eventSubmission.Date.Add(eventSubmission.Time)) > 0)
         {
             ModelState.AddModelError("Date", "Date must be in the future");
             ModelState.AddModelError("Time", "Time must be in the future");
             return(View("NewEvent"));
         }
         User thisUser = dbContext.Users.FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("LoggedInUserId"));
         eventSubmission.Coordinator = thisUser;
         eventSubmission.UserId      = thisUser.UserId;
         dbContext.Events.Add(eventSubmission);
         RSVP thisRSVP = new RSVP {
             EventId = eventSubmission.EventId,
             UserId  = thisUser.UserId,
         };
         ViewBag.User = thisUser;
         dbContext.RSVPs.Add(thisRSVP);
         dbContext.SaveChanges();
         return(Redirect($"/Event/{eventSubmission.EventId}"));
     }
     else
     {
         return(View("NewEvent"));
     }
 }
Esempio n. 2
0
        public IActionResult Leave(int eventId)
        {
            Event thisEvent = dbContext.Events.FirstOrDefault(e => e.EventId == eventId);
            User  thisUser  = dbContext.Users.Where(u => u.UserId == HttpContext.Session.GetInt32("LoggedInUserId")).FirstOrDefault();
            RSVP  thisRSVP  = dbContext.RSVPs
                              .Where(r => r.EventId == eventId && r.UserId == (int)HttpContext.Session.GetInt32("LoggedInUserId"))
                              .FirstOrDefault();

            dbContext.RSVPs.Remove(thisRSVP);
            dbContext.SaveChanges();
            return(RedirectToAction("Home"));
        }
Esempio n. 3
0
        public IActionResult Delete(int eventId)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") == null)
            {
                return(RedirectToAction("Index"));
            }
            Event thisEvent = dbContext.Events
                              .Include(e => e.Coordinator)
                              .Include(e => e.Attendees)
                              .ThenInclude(r => r.User)
                              .FirstOrDefault(a => a.EventId == eventId);

            dbContext.Events.Remove(thisEvent);
            dbContext.SaveChanges();
            return(RedirectToAction("Home"));
        }
Esempio n. 4
0
        public IActionResult Event(int eventId)
        {
            int?LoggedInUserId = HttpContext.Session.GetInt32("LoggedInUserId");

            if (LoggedInUserId == null)
            {
                return(RedirectToAction("Index"));
            }
            var thisUser = dbContext.Users.FirstOrDefault(u => u.UserId == (int)LoggedInUserId);

            ViewBag.thisUser = thisUser;
            Event thisEvent = dbContext.Events
                              .Include(e => e.Coordinator)
                              .Include(e => e.Attendees)
                              .ThenInclude(r => r.User)
                              .FirstOrDefault(e => e.EventId == eventId);

            ViewBag.Coordinator = thisEvent.Coordinator;
            return(View("Event", thisEvent));
        }
Esempio n. 5
0
        public IActionResult Join(int eventId)
        {
            Event       thisEvent     = dbContext.Events.SingleOrDefault(e => e.EventId == eventId);
            User        thisUser      = dbContext.Users.Where(u => u.UserId == HttpContext.Session.GetInt32("LoggedInUserId")).FirstOrDefault();
            List <RSVP> thisUserRSVPs = thisUser.RSVPs;
            DateTime    thisEventEnd  = thisEvent.EndTime;

            foreach (var rsvp in thisUser.RSVPs)
            {
                DateTime end = thisEventEnd;
                if (end.CompareTo(thisEventEnd) > 0 && rsvp.Event.Date.CompareTo(thisEvent.Date.Add(thisEvent.Time)) < 0)
                {
                    return(RedirectToAction("Home"));
                }
            }
            RSVP thisRSVP = new RSVP {
                EventId = thisEvent.EventId,
                UserId  = thisUser.UserId,
            };

            thisUser.RSVPs.Add(thisRSVP);
            dbContext.SaveChanges();
            return(RedirectToAction("Home"));
        }