Example #1
0
 public ActionResult Activ(Activ activ)
 {
     if (ModelState.IsValid)
     {
         db.Activs.Add(activ);
         db.SaveChanges();
     }
     ViewBag.Activs      = db.Activs.Include(s => s.Department);
     ViewBag.Departments = new SelectList(db.Departments, "Id", "Name");
     return(View(activ));
 }
Example #2
0
        public IActionResult RSVP()
        {
            Int32.TryParse(RouteData.Values["id"].ToString(), out int actId);

            if (HttpContext.Session.Keys.Contains("userID"))
            {
                Activ specActivity = dbContext.Activities.Include(a => a.Guests).FirstOrDefault(a => a.Id == actId);
                User  loggedIn     = dbContext.Users.Include(user => user.plans).ThenInclude(plan => plan.Activity).Where(user => user.Id == HttpContext.Session.GetInt32("userID")).FirstOrDefault();


                DateTime startOrig;
                DateTime endOrig;

                DateTime startNew;
                DateTime endNew;

                foreach (var plan in loggedIn.plans)
                {
                    startOrig = plan.Activity.Date;
                    endOrig   = plan.Activity.Date + plan.Activity.Duration;

                    startNew = specActivity.Date;
                    endNew   = specActivity.Date + specActivity.Duration;
                    System.Console.WriteLine($"**** Is new ending {endNew} before the old start {startOrig} or is the new start {startNew} after the old end {endOrig}???");
                    System.Console.WriteLine("endNew.CompareTo(startOrig) < 0 " + endNew.CompareTo(startOrig));
                    System.Console.WriteLine("startNew.CompareTo(endOrig) > 0 " + startNew.CompareTo(endOrig));
                    if ((endNew.CompareTo(startOrig) < 0) || (startNew.CompareTo(endOrig) > 0))
                    {
                        System.Console.WriteLine("pass");
                    }
                    else
                    {
                        System.Console.WriteLine($"conflict");
                        TempData["conflict"] = true;
                        return(RedirectToAction("Wall"));
                    }
                }

                Plan newPlan = new Plan();
                newPlan.User     = loggedIn;
                newPlan.Activity = specActivity;

                dbContext.Add(newPlan);
                specActivity.Guests.Add(newPlan);
                dbContext.SaveChanges();

                return(RedirectToAction("Wall"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #3
0
        public IActionResult UnJoinToActiv(int ActivId)
        {
            Activ       retrievedActiv = dbContext.Activs.FirstOrDefault(w => w.ActivId == ActivId);
            User        loggedUser     = dbContext.Users.FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("logged"));
            List <Join> retrievedJoins = dbContext.Joins
                                         .Where(r => r.ActivId == retrievedActiv.ActivId).ToList();
            Join retrievedJoin = retrievedJoins.FirstOrDefault(r => r.UserId == loggedUser.UserId);

            dbContext.Remove(retrievedJoin);
            dbContext.SaveChanges();
            PopulateBag();
            return(RedirectToAction("Dashboard"));
        }
Example #4
0
        public IActionResult ViewActiv(int ActivId)
        {
            int flag = CheckLogged();

            if (flag == 0)
            {
                return(View("Index"));
            }
            Activ retrievedActiv = dbContext.Activs.FirstOrDefault(w => w.ActivId == ActivId);

            GetActivJoiners(ActivId);
            return(View("ViewActiv", retrievedActiv));
        }
Example #5
0
        public IActionResult JoinToActiv(int ActivId)
        {
            Activ retrievedActiv = dbContext.Activs.FirstOrDefault(w => w.ActivId == ActivId);
            User  loggedUser     = dbContext.Users.FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("logged"));
            Join  newJoin        = new Join()
            {
                UserId  = loggedUser.UserId,
                ActivId = retrievedActiv.ActivId,
                User    = loggedUser,
                Activ   = retrievedActiv,
            };

            dbContext.Joins.Add(newJoin);
            dbContext.SaveChanges();
            PopulateBag();
            return(RedirectToAction("Dashboard"));
        }
Example #6
0
 public IActionResult ProcessActiv(Activ NewActivity)
 {
     if (ModelState.IsValid)
     {
         if (NewActivity.ActivDate < DateTime.Now)
         {
             TempData["alertMessage"] = "<p style='color:red;'>Date of Activ must be in the future.</p>";
             return(RedirectToAction("NewActivity"));
         }
         User loggedUser = dbContext.Users.FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("logged"));
         NewActivity.Creator = loggedUser;
         NewActivity.UserId  = loggedUser.UserId;
         dbContext.Activs.Add(NewActivity);
         dbContext.SaveChanges();
         return(RedirectToAction("ViewActiv", new { ActivId = NewActivity.ActivId }));
     }
     return(View("NewActivity"));
 }
Example #7
0
        public IActionResult UNRSVP()
        {
            Int32.TryParse(RouteData.Values["id"].ToString(), out int actId);

            if (HttpContext.Session.Keys.Contains("userID"))
            {
                Activ specActivity = dbContext.Activities.Include(a => a.Guests).ThenInclude(guest => guest.User).FirstOrDefault(a => a.Id == actId);
                User  loggedIn     = dbContext.Users.FirstOrDefault(user => user.Id == HttpContext.Session.GetInt32("userID"));

                Plan specPlan = specActivity.Guests.FirstOrDefault(guest => guest.User == loggedIn);


                dbContext.Plans.Remove(specPlan);
                dbContext.SaveChanges();

                return(RedirectToAction("Wall"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
Example #8
0
        public IActionResult Delete()
        {
            Int32.TryParse(RouteData.Values["id"].ToString(), out int actId);

            if (HttpContext.Session.Keys.Contains("userID"))
            {
                List <Plan> relatedPlans = dbContext.Plans.Include(p => p.Activity).Where(p => p.Activity.Id == actId).ToList();
                Activ       specActivity = relatedPlans[0].Activity;

                foreach (var specPlan in relatedPlans)
                {
                    dbContext.Remove(specPlan);
                }

                dbContext.Remove(specActivity);
                dbContext.SaveChanges();

                return(RedirectToAction("Wall"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
 public void add_tolist(Activ c)
 {
     this.list.Add(c);
 }
Example #10
0
        public IActionResult SubmitActivity(Activ sub)
        {
            User     loggedIn = dbContext.Users.Include(user => user.plans).ThenInclude(plan => plan.Activity).Where(user => user.Id == HttpContext.Session.GetInt32("userID")).FirstOrDefault();
            DateTime startOrig;
            DateTime endOrig;

            DateTime startNew;
            DateTime endNew;

            if (sub.TimeUnit == "hours")
            {
                sub.Duration = sub.Duration / 24;
            }
            else if (sub.TimeUnit == "minutes")
            {
                sub.Duration = sub.Duration / (60 * 24);
            }
            foreach (var plan in loggedIn.plans)
            {
                startOrig = plan.Activity.Date;
                endOrig   = plan.Activity.Date + plan.Activity.Duration;

                startNew = sub.Date.Date + sub.Time;
                endNew   = sub.Date.Date + sub.Time + sub.Duration;
                System.Console.WriteLine($"**** Is new ending {endNew} before the old start {startOrig} or is the new start {startNew} after the old end {endOrig}???");
                System.Console.WriteLine("endNew.CompareTo(startOrig) < 0 " + endNew.CompareTo(startOrig));
                System.Console.WriteLine("startNew.CompareTo(endOrig) > 0 " + startNew.CompareTo(endOrig));
                if ((endNew.CompareTo(startOrig) < 0) || (startNew.CompareTo(endOrig) > 0))
                {
                    System.Console.WriteLine("pass");
                }
                else
                {
                    ModelState.AddModelError("Date", "Schedule conflict with your events!");
                }
            }
            if (sub.Date + sub.Time <= DateTime.Now)
            {
                ModelState.AddModelError("Date", "Date must be in the future!");
            }

            if (ModelState.IsValid)
            {
                dbContext.Add(sub);
                dbContext.SaveChanges();

                Plan newPlan = new Plan();
                newPlan.User             = loggedIn;
                newPlan.Activity         = sub;
                newPlan.Activity.Date    = newPlan.Activity.Date.Date + sub.Time;
                newPlan.Activity.Creator = loggedIn;
                newPlan.Activity.Guests  = new List <Plan>();
                System.Console.WriteLine(newPlan.Activity.Guests);

                dbContext.Add(newPlan);
                newPlan.Activity.Guests.Add(newPlan);
                dbContext.SaveChanges();

                return(RedirectToAction("Wall"));
            }

            return(View("New"));
        }