コード例 #1
0
        public IActionResult Create(WeddingPlanned model)
        {
            if (ActiveUser == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (ModelState.IsValid)
            {
                // Create WeddingPlanned
                WeddingPlanned wedding = new WeddingPlanned()
                {
                    WedderOne = model.WedderOne,
                    WedderTwo = model.WedderTwo,
                    Date      = model.Date,
                    Address   = model.Address,
                    Planner   = ActiveUser
                                // created_at = DateTime.Now, // Set in the constructor()
                                // updated_at = DateTime.Now, // Set in the constructor()
                };

                // Entity Framework is smart enough to look for a DbSet that contains the appropriate object type and save the new entry there. If our database does contain multiple tables that store the same object type it does become necessary to target a specific DbSet
                _context.Weddings_Planned.Add(wedding); // Staging
                // OR _context.Add(wedding);
                _context.SaveChanges();                 // Commit changes
                // return Json(wedding);
                return(RedirectToAction("Index"));
            }
            return(View("New"));
        }
コード例 #2
0
        public IActionResult Delete(int id)
        {
            if (ActiveUser == null)
            {
                return(RedirectToAction("Index", "Home"));
            }
            WeddingPlanned retrievedWedding = _context.Weddings_Planned.SingleOrDefault(w => w.WeddingId == id);

            _context.Weddings_Planned.Remove(retrievedWedding);
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }