Esempio n. 1
0
        public IActionResult ActivityDetails(int activityid)
        {
            System.Console.WriteLine($"In ActivityDetails - {activityid} -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

            int?userid = HttpContext.Session.GetInt32("UserId");

            if (userid == null)
            {
                return(RedirectToAction("Index"));
            }

            ActivityCenter.Models.Activity va = dbContext.Activities
                                                .Include(u => u.Creator)
                                                .Include(ua => ua.UserList)
                                                .ThenInclude(u => u.User)
                                                .FirstOrDefault(a => a.ActivityId == activityid);

            // Wedding vw = dbContext.Weddings
            //     //.Include(u => u.UserId)
            //     .Include(r => r.RSVPs)
            //     .ThenInclude(u => u.User)
            //     .FirstOrDefault(w => w.WeddingId == weddingid);

            ViewBag.UserId = (int)userid;

            return(View(va));
        }
Esempio n. 2
0
        public IActionResult postactivity(ActivityCenter.Models.Activity activity)
        {
            activity.UserId  = HttpContext.Session.GetInt32("User").GetValueOrDefault();
            activity.Planner = dbContext.Users.FirstOrDefault(user => user.UserId == HttpContext.Session.GetInt32("User"));
            if (ModelState.IsValid)
            {
                DateTime combined = activity.Datetime.Add(activity.time);
                System.Console.WriteLine(combined);
                if (combined < DateTime.Now)
                {
                    ModelState.AddModelError("Datetime", "Date and Time must be in the future");
                    return(View("addactivity"));
                }


                dbContext.Add(activity);
                dbContext.SaveChanges();

                ViewBag.UserId = HttpContext.Session.GetInt32("User");

                Rsvp thisrsvp = new Rsvp
                {
                    UserId     = ViewBag.UserId,
                    ActivityId = activity.ActivityId
                };
                dbContext.Add(thisrsvp);
                dbContext.SaveChanges();
                return(RedirectToAction("home"));
            }
            else
            {
                System.Console.WriteLine("Return to Create");
                return(View("addactivity"));
            }
        }
Esempio n. 3
0
 public IActionResult activityinfo(int activityId)
 {
     ViewBag.UserId = HttpContext.Session.GetInt32("User");
     ActivityCenter.Models.Activity thisactivity = dbContext.Activities.Include(act => act.Rsvps)
                                                   .ThenInclude(u => u.user).Include(n => n.Planner).SingleOrDefault(a => a.ActivityId == activityId);
     ViewBag.Activity = thisactivity;
     return(View("showactivity"));
 }
Esempio n. 4
0
        public IActionResult CreateActivity(ActivityCenter.Models.Activity activity)
        {
            foreach (string k in HttpContext.Request.Form.Keys)
            {
                System.Console.WriteLine(k);
                System.Console.WriteLine(HttpContext.Request.Form[k].ToString());
            }
            System.Console.WriteLine("In NewWedding - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.Title} - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.Description} - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.ActivityDate}- @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.ActivityTime} - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.Duration} - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"{activity.DurationUnit} - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            System.Console.WriteLine($"End Time - @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

            int?userid = HttpContext.Session.GetInt32("UserId");

            if (userid == null)
            {
                return(RedirectToAction("Index"));
            }

            if (ModelState.IsValid)
            {
                // If a User exists with provided email
                if (activity.ActivityDate.Date <= DateTime.Now.Date && activity.ActivityTime.TimeOfDay <= DateTime.Now.TimeOfDay)
                {
                    // Manually add a ModelState error to the Email field, with provided
                    // error message
                    ModelState.AddModelError("ActivityDate", "Date has to be in the future!");

                    ViewBag.UserId = (int)userid;

                    // You may consider returning to the View at this point
                    return(View("NewActivity"));
                }

                dbContext.Activities.Add(activity);
                // OR dbContext.Users.Add(newUser);
                dbContext.SaveChanges();

                ViewBag.UserId = (int)userid;

                //return RedirectToAction("DashBoard");
                return(Redirect($"activitydetails/{activity.ActivityId}"));
            }

            ViewBag.UserId = (int)userid;

            return(View("NewActivity"));
        }
Esempio n. 5
0
        public IActionResult delete(int activityId)
        {
            ActivityCenter.Models.Activity thisactivity = dbContext.Activities.SingleOrDefault(act => act.ActivityId == activityId);


            if (HttpContext.Session.GetInt32("User") == thisactivity.UserId)
            {
                dbContext.Activities.Remove(thisactivity);
                dbContext.SaveChanges();
            }


            return(RedirectToAction("home"));
        }
Esempio n. 6
0
        public IActionResult DeleteActivity(int activityId)
        {
            User userInDb = GetUser();

            if (userInDb == null)
            {
                return(Redirect("/"));
            }
            Activity delete = dbContext.Activities.FirstOrDefault(w => w.ActivityId == activityId);

            dbContext.Activities.Remove(delete);
            dbContext.SaveChanges();
            return(RedirectToAction("Dashboard"));
        }
Esempio n. 7
0
        public IActionResult DisplayActivity(int activityId)
        {
            User userInDb = GetUser();

            if (userInDb == null)
            {
                return(Redirect("/"));
            }
            ViewBag.User = userInDb;
            Activity displaying = dbContext.Activities
                                  .Include(w => w.Guests)
                                  .ThenInclude(gl => gl.Participants)
                                  .Include(w => w.Planner)
                                  .FirstOrDefault(w => w.ActivityId == activityId);

            return(View(displaying));
        }
Esempio n. 8
0
        public IActionResult DeleteActivity(int activityid)
        {
            System.Console.WriteLine($"In DeleteActivity - {activityid} -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");

            int?userid = HttpContext.Session.GetInt32("UserId");

            if (userid == null)
            {
                return(RedirectToAction("Index"));
            }

            ActivityCenter.Models.Activity dactivity = dbContext.Activities.FirstOrDefault(a => a.ActivityId == activityid);
            dbContext.Activities.Remove(dactivity);
            dbContext.SaveChanges();

            ViewBag.UserId = (int)userid;

            return(RedirectToAction("DashBoard"));
        }
Esempio n. 9
0
        public IActionResult CreateActivity(Activity newActivity)
        {
            User userInDb = GetUser();

            if (userInDb == null)
            {
                return(Redirect("/"));
            }
            if (ModelState.IsValid)
            {
                newActivity.UserId = userInDb.UserId;
                dbContext.Activities.Add(newActivity);
                dbContext.SaveChanges();
                GuestList g = new GuestList();
                g.UserId     = userInDb.UserId;
                g.ActivityId = newActivity.ActivityId;
                dbContext.GuestLists.Add(g);
                dbContext.SaveChanges();
                Console.Write("NEW ACTIVITY CREATED \n");
                return(Redirect($"/activity/{newActivity.ActivityId}"));
            }
            return(View("NewActivity"));
        }