示例#1
0
 public IActionResult AddWedding(WeddingUserW fromForm)
 {
     if (ModelState.IsValid)
     {
         int?IdFromSession = HttpContext.Session.GetInt32("UserId");
         if (IdFromSession == null)
         {
             return(RedirectToAction("LoginUser"));
         }
         if (fromForm.wedding.Date < DateTime.Now)
         {
             ModelState.AddModelError("Date", "Date must be in the future");
             return(RedirectToAction("NewWedding"));
         }
         Wedding ourwed   = new Wedding();
         User    redshirt = dbContext.Users
                            .FirstOrDefault(u => u.UserId == IdFromSession);
         // fromForm.wedding.Creator = redshirt;
         fromForm.wedding.UserId = (int)IdFromSession;
         dbContext.Weddings.Add(fromForm.wedding);
         dbContext.SaveChanges();
         return(RedirectToAction("ViewWedding", new{ WeddingId = fromForm.wedding.WeddingId }));
     }
     else
     {
         return(View("NewWedding"));
     }
 }
示例#2
0
        public IActionResult Dashboard()
        {
            int?IdFromSession = HttpContext.Session.GetInt32("UserId");

            if (IdFromSession == null)
            {
                return(RedirectToAction("LoginUser"));
            }
            WeddingUserW vMod = new WeddingUserW();

            vMod.Allweddings = dbContext.Weddings
                               .Where(w => w.Date > DateTime.Now)
                               .Include(w => w.Guests)
                               .ThenInclude(g => g.User).ToList();

            User ourdude = dbContext.Users
                           .FirstOrDefault(u => u.UserId == HttpContext.Session.GetInt32("UserId"));

            vMod.user = ourdude;

            return(View(vMod));
        }