public IActionResult Create(WeddingForm form)
        {
            if (HttpContext.Session.GetInt32("LoggedInUserId") is null)
            {
                return(RedirectToAction("Index", "LoginReg"));
            }

            if (ModelState.IsValid)
            {
                Wedding newWedding = new Wedding()
                {
                    WedderOne = form.WedderOne,
                    WedderTwo = form.WedderTwo,
                    Date      = form.Date,
                    Address   = form.Address.Replace(" ", "+"),
                    UserId    = (int)HttpContext.Session.GetInt32("LoggedInUserId")
                };

                dbContext.Add(newWedding);
                dbContext.SaveChanges();

                int newWeddingId = dbContext.Weddings
                                   .Last(w => w.UserId == (int)HttpContext.Session.GetInt32("LoggedInUserId")).WeddingId;
                return(RedirectToAction("ViewWedding", new { weddingId = newWeddingId }));
            }
            return(View("New"));
        }
Ejemplo n.º 2
0
 public IActionResult UpdateWedding(WeddingForm weddingForm)
 {
     _logger.LogInformation($"=== EditWeddingPost ===");
     TempData["WeddingToEdit"] = weddingForm.WeddingId;
     if (!ModelState.IsValid)
     {
         _logger.LogInformation($"=== EditWeddingPost MODEL STATE IS NOT VALID ===");
         return(View("EditWedding", weddingForm));
     }
     _dbContext.Weddings.Update(new Wedding(weddingForm));
     _dbContext.SaveChanges();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 3
0
 public IActionResult CreateWedding(WeddingForm formWedding, Wedding newWedding)
 {
     if (ModelState.IsValid)
     {
         int weddingDate = formWedding.Date.DayOfYear;
         int Today       = DateTime.Now.DayOfYear;
         if (weddingDate < Today)
         {
             ModelState.AddModelError("Date", "Must create a wedding for a future date.");
             return(View("WeddingPlan"));
         }
         int?idUser = HttpContext.Session.GetInt32("LoggedID");
         newWedding.Location = formWedding.Address;
         newWedding.UserId   = (int)idUser;
         dbContext.Add(newWedding);
         dbContext.SaveChanges();
         // SELECTING ADDED WEDDING ID
         Wedding thisWeddingId = dbContext.Weddings
                                 .Where(w => w.WeddingId == newWedding.WeddingId)
                                 .SingleOrDefault();
         return(RedirectToAction("WeddingInfo", new { weddingId = thisWeddingId.WeddingId }));
     }
     return(View("WeddingPlan"));
 }