예제 #1
0
        public IActionResult CreateWedding(WeddingViewModel NewWedding)
        {
            int?id = HttpContext.Session.GetInt32("Id");

            if (ModelState.IsValid)
            {
                weddings Nwedding = new weddings()
                {
                    usersid    = (int)id,
                    wedder_1   = NewWedding.wedder_1,
                    wedder_2   = NewWedding.wedder_2,
                    date       = NewWedding.date,
                    location   = NewWedding.address,
                    created_at = DateTime.Now,
                    updated_at = DateTime.Now
                };
                if (NewWedding.date < DateTime.Today)
                {
                    ModelState.AddModelError("date", "Marry in the past? are you sure?");
                    return(View("createwedding"));
                }
                _context.Add(Nwedding);
                _context.SaveChanges();
                return(RedirectToAction("Wedding"));
            }
            return(View("createwedding"));
        }
        public IActionResult DisplayWedding(int id)
        {
            weddings wedding = _context.weddings.Where(w => w.id == id).Include(w => w.weddings_has_users).ThenInclude(u => u.user).SingleOrDefault();

            ViewBag.address = wedding.address;
            ViewBag.wedders = wedding.wedders;
            ViewBag.date    = wedding.date;
            return(View("DisplayWedding", wedding));
        }
 public IActionResult ValidateWedding(WeddingViewModels weddingMod)
 {
     if (ModelState.IsValid)
     {
         weddings wedding = CreateWedding(weddingMod);
         int      id      = wedding.id;
         return(Redirect($"wedding_display/{id}"));
     }
     return(View("PlanWedding"));
 }
        public IActionResult RemoveUserFromEvent(int weddingId)
        {
            int?               userId       = HttpContext.Session.GetInt32(key: "userId");
            int                user_id      = (int)userId;
            weddings           wedding      = _context.weddings.Where(w => w.id == weddingId).SingleOrDefault();
            weddings_has_users wedding_user = _context.weddings_has_users.Where(w => w.users_id == user_id).Where(w => w.weddings_id == weddingId).SingleOrDefault();

            wedding.guests -= 1;
            _context.weddings_has_users.Remove(wedding_user);
            _context.SaveChanges();
            return(RedirectToAction("WeddingDash"));
        }
예제 #5
0
        public IActionResult Weddinginfo(int weddingid)
        {
            // List<weddings> Weddinginfo=_context.weddings.Include(s=>s.guests).Where(d=>d.id == weddingid).ToList();
            // List<guests> Weddinginfo = _context.guests.Include(s=>s.user).Include(z=>z.wedding)
            // .Where(d=>d.weddingsid == weddingid).ToList();
            weddings Weddinginfo = _context.weddings.Where(d => d.id == weddingid).Include(s => s.guests)
                                   .ThenInclude(z => z.user).First();

            // foreach (var guest in Weddinginfo.guests)
            // {
            //     System.Console.WriteLine(guest.user.first_name);
            // }
            ViewBag.Weddinginfo = Weddinginfo;
            return(View("weddinginfo"));
        }
        public IActionResult AddUserToEvent(int weddingId)
        {
            int?     userId  = HttpContext.Session.GetInt32(key: "userId");
            int      user_id = (int)userId;
            users    user    = _context.users.Where(u => u.id == user_id).SingleOrDefault();
            weddings wedding = _context.weddings.Where(w => w.id == weddingId).SingleOrDefault();

            wedding.guests += 1;
            weddings_has_users addGuest = new weddings_has_users
            {
                weddings_id = wedding.id,
                users_id    = user_id
            };

            _context.Add(addGuest);
            _context.SaveChanges();
            return(RedirectToAction("WeddingDash"));
        }
        public weddings CreateWedding(WeddingViewModels weddingMod)
        {
            string   wedders    = $"{weddingMod.wedder_one} & {weddingMod.wedder_two}";
            int?     userId     = HttpContext.Session.GetInt32(key: "userId");
            int      user_id    = (int)userId;
            weddings addWedding = new weddings
            {
                wedders    = wedders,
                date       = weddingMod.Date,
                address    = weddingMod.wedding_address,
                guests     = 0,
                created_by = user_id
            };

            _context.Add(addWedding);
            _context.SaveChanges();
            return(addWedding);
        }
        public IActionResult DeleteWedding(int weddingId)
        {
            int?num = HttpContext.Session.GetInt32("userId");

            if (num == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            int      user_id = (int)num;
            weddings wedding = _context.weddings.Where(w => w.id == weddingId).SingleOrDefault();

            if (user_id != wedding.created_by)
            {
                return(RedirectToAction("Index", "Home"));
            }
            _context.weddings.Remove(wedding);
            _context.SaveChanges();
            return(RedirectToAction("WeddingDash"));
        }