Exemple #1
0
 public IActionResult SaveWedding(WeddingViewModel newWedding)
 {
     if (ModelState.IsValid)
     {
         WeddingCreator NewWedding = new WeddingCreator
         {
             WeddingOne     = newWedding.WeddingOne,
             WeddingTwo     = newWedding.WeddingTwo,
             Date           = newWedding.Date,
             WeddingAddress = newWedding.WeddingAddress,
             Created_at     = DateTime.Now,
             Updated_at     = DateTime.Now,
             UserId         = (int)HttpContext.Session.GetInt32("UserId")
         };
         List <Guest> Guests = _context.Guests
                               .Include(user => user.User)
                               .Include(wedding => wedding.Wedding)
                               .ToList();
         _context.Weddings.Add(NewWedding);
         ViewBag.allweddings = new List <string>();
         _context.SaveChanges();
         return(RedirectToAction("AllWeddings"));
     }
     else
     {
         ViewBag.Errors = ModelState.Values;
         return(View("CreateWedding"));
     }
 }
Exemple #2
0
        public IActionResult OneWedding(int id)
        {
            WeddingCreator OneWedding = _context.Weddings.Where(wedding => wedding.WeddingId == id).Include(x => x.Guests).ThenInclude(x => x.User).SingleOrDefault();

            ViewBag.OneWedding = OneWedding;
            return(View("OneWedding"));
        }
Exemple #3
0
        public IActionResult Delete(int id)
        {
            WeddingCreator RetrievedWedding = _context.Weddings.SingleOrDefault(wedding => wedding.WeddingId == id);
            List <Guest>   RemoveGuests     = _context.Guests.Where(guests => guests.WeddingId == id).ToList();

            foreach (var guest in RemoveGuests)
            {
                _context.Guests.Remove(guest);
            }
            _context.Weddings.Remove(RetrievedWedding);
            _context.SaveChanges();
            ViewBag.allweddings = new List <string>();
            return(RedirectToAction("AllWeddings"));
        }