示例#1
0
        public IActionResult ViewActivity(int ActivityID)
        {
            int?userID = HttpContext.Session.GetInt32("userID");

            if (userID == null)
            {
                TempData["error"] = "You need to be logged in to view this page";
                return(RedirectToAction("Index"));
            }
            AnActivity retreivedActivity = dbContext.Activities
                                           .Include(g => g.AllParticipants)
                                           .ThenInclude(u => u.User)
                                           .FirstOrDefault(a => a.ActivityID == ActivityID);

            // System.Console.WriteLine(DateTime.Now);
            // System.Console.WriteLine(retreivedActivity.Date);
            if (DateTime.Now > retreivedActivity.Time)
            {
                TempData["passedDue"] = "Activity has unfortunately finished";
                return(RedirectToAction("DeleteActivity", new{ ActivityID = ActivityID }));
            }

            User retreivedUser = dbContext.Users.FirstOrDefault(u => u.UserID == userID);

            ViewBag.User = retreivedUser;

            ViewBag.whomadeit = dbContext.Users.FirstOrDefault(u => u.UserID == retreivedActivity.UserID);

            return(View("ViewActivity", retreivedActivity));
        }
示例#2
0
        public IActionResult CreateActivity(AnActivity newActivity)
        {
            int?userID = HttpContext.Session.GetInt32("userID");

            if (userID == null)
            {
                TempData["error"] = "You need to be logged in to view this page";
                return(RedirectToAction("Index"));
            }
            User retreivedUser = dbContext.Users.FirstOrDefault(u => u.UserID == userID);


            // System.Console.WriteLine(newActivity.Date);
            // System.Console.WriteLine(newActivity.Time);
            System.Console.WriteLine(ModelState.IsValid);
            if (ModelState.IsValid)
            {
                if (newActivity.Time < DateTime.Now)
                {
                    ModelState.AddModelError("Date", "Date needs to be in the future!");
                    return(View("NewActivity"));
                }
                newActivity.CreatorNameFirst = retreivedUser.FirstName;
                newActivity.CreatorNameLast  = retreivedUser.LastName;
                newActivity.UserID           = (int)userID;
                dbContext.Activities.Add(newActivity);
                dbContext.SaveChanges();
                // System.Console.WriteLine(newActivity.ActivityID);
                // HttpContext.Session.SetInt32("LastActivityCreated_activityID", newActivity.ActivityID);
                return(RedirectToAction("Dashboard"));
            }
            return(View("NewActivity"));
        }
示例#3
0
        public IActionResult Delete(int id)
        {
            AnActivity thisActivity = dbContext.Activities.FirstOrDefault(a => a.Activityid == id);

            dbContext.Remove(thisActivity);
            dbContext.SaveChanges();
            return(RedirectToAction("Home"));
        }
示例#4
0
        public IActionResult Delete(int AnActivityId)
        {
            AnActivity ActivityToDelete = db.AnActivities.FirstOrDefault(a => a.AnActivityId == AnActivityId);

            db.AnActivities.Remove(ActivityToDelete);
            db.SaveChanges();
            return(RedirectToAction("Home"));
        }
示例#5
0
        public IActionResult Activity(int id)
        {
            AnActivity thisActivity = dbContext.Activities
                                      .Include(a => a.Creator)
                                      .Include(a => a.RSVPList)
                                      .ThenInclude(list => list.User)
                                      .FirstOrDefault(a => a.Activityid == id);

            ViewBag.Activity = thisActivity;
            @ViewBag.User    = loggedUser;
            return(View());
        }
示例#6
0
 public IActionResult SubmitActivity(int id, AnActivity newActivity)
 {
     if (ModelState.IsValid)
     {
         newActivity.Creator = loggedUser;
         dbContext.Activities.Add(newActivity);
         dbContext.SaveChanges();
         return(RedirectToAction("Home"));
     }
     ViewBag.User = loggedUser;
     return(View("NewActivity"));
 }
示例#7
0
        public IActionResult AnActivity(int AnActivityId)
        {
            if (!isLoggedIn)
            {
                return(RedirectToAction("SignIn"));
            }
            AnActivity thisAnActivity = db.AnActivities
                                        .Include(x => x.AnActivityCreator)
                                        .Include(p => p.RelatedParticipants)
                                        .ThenInclude(rel => rel.Users)
                                        .FirstOrDefault(a => a.AnActivityId == AnActivityId);

            return(View("AnActivity", thisAnActivity));
        }
示例#8
0
        public IActionResult DeleteActivity(int ActivityID)
        {
            int?userID = HttpContext.Session.GetInt32("userID");

            if (userID == null)
            {
                TempData["error"] = "You need to be logged in to view this page";
                return(RedirectToAction("Index"));
            }
            AnActivity retreivedActivity = dbContext.Activities.FirstOrDefault(a => a.ActivityID == ActivityID);

            dbContext.Activities.Remove(retreivedActivity);
            dbContext.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }
示例#9
0
 public IActionResult CreateActivity(AnActivity newAnActivity)
 {
     if (ModelState.IsValid)
     {
         if (newAnActivity.Date <= DateTime.Now)
         {
             ModelState.AddModelError("Date", "Activity must be a future date.");
             return(View("NewActivity", newAnActivity));
         }
         newAnActivity.UserId = (int)uid;
         db.AnActivities.Add(newAnActivity);
         db.SaveChanges();
         return(RedirectToAction("AnActivity", new { AnActivityId = newAnActivity.AnActivityId }));
     }
     return(View("NewActivity", newAnActivity));
 }
示例#10
0
        public IActionResult JoinActivity(int ActivityID)
        {
            int?userID = HttpContext.Session.GetInt32("userID");

            if (userID == null)
            {
                TempData["error"] = "You need to be logged in to view this page";
                return(RedirectToAction("Index"));
            }
            AnActivity  retreivedActivity = dbContext.Activities.FirstOrDefault(a => a.ActivityID == ActivityID);
            Participant newJoin           = new Participant();

            newJoin.UserID     = (int)userID;
            newJoin.ActivityID = retreivedActivity.ActivityID;
            newJoin.Activity   = retreivedActivity;
            newJoin.User       = dbContext.Users.FirstOrDefault(u => u.UserID == userID);
            dbContext.Add(newJoin);
            dbContext.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }