public IActionResult Create(WeddingsView WedView) { if (ModelState.IsValid) { System.Console.WriteLine($"Line 50 Weddings-Valid"); Weddings newWed = new Weddings { WedderOne = WedView.WedderOne, WedderTwo = WedView.WedderTwo, Date = WedView.Date, Address = WedView.Address, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; _context.Weddings.Add(newWed); _context.SaveChanges(); // Get new Wedding back; Weddings Wed = new Weddings(); Wed = _context.Weddings .Include(w => w.Invitations) .ThenInclude(b => b.Guests) .SingleOrDefault(c => c.WedderOne == WedView.WedderOne && c.WedderTwo == WedView.WedderTwo); System.Console.WriteLine($"Wedding Wedding {Wed}"); ViewBag.Wedding = Wed; return(View("Dashboard")); } else { ViewBag.Errors = ModelState.Values; return(RedirectToAction("ToNew")); } }
public IActionResult AddWedding(WeddingsValidate weddingvalidator) { int?UserID = HttpContext.Session.GetInt32("UserID"); if (ModelState.IsValid) { Weddings myWedding = new Weddings(); myWedding.wedder_one = weddingvalidator.wedder_one; myWedding.wedder_two = weddingvalidator.wedder_two; myWedding.date = weddingvalidator.date; myWedding.created_at = DateTime.Now; myWedding.updated_at = DateTime.Now; myWedding.usersid = (int)UserID; myWedding.address = weddingvalidator.address; if (myWedding.date < DateTime.Today) { ModelState.AddModelError("date", "Wedding creation has to be in the future, nice try!"); // ViewBag.error = "LOL, Nice try!"; return(View("PlanWedding")); } ; _context.Add(myWedding); _context.SaveChanges(); return(RedirectToAction("Dashboard")); } else { return(View("PlanWedding")); } }
public IActionResult JoinWedding(int WeddingId) { // Get user object var CurrentUser = _context.Users.Where(u => u.UserId == HttpContext.Session.GetInt32("CurrentUserId")).Include(w => w.WeddingsAttending).ThenInclude(x => x.Weddings).SingleOrDefault(); // Check if user is already attending the wedding. foreach (var wedding in CurrentUser.WeddingsAttending) { if (wedding.WeddingsId == WeddingId) { TempData["RsvpError"] = "You're already attending that wedding!"; return(RedirectToAction("Account")); } } // Change UpdatedAt field in User object CurrentUser.UpdatedAt = DateTime.Now; // Get wedding object in order to increment NumGuests Weddings SelectedWedding = _context.Weddings.Where(w => w.WeddingsId == WeddingId).SingleOrDefault(); SelectedWedding.NumGuests++; // Add user to weddings attending list. Atendees NewAtendee = new Atendees { User = CurrentUser, Weddings = SelectedWedding }; _context.Atendees.Add(NewAtendee); _context.SaveChanges(); return(RedirectToAction("ShowWedding", new { WeddingId = WeddingId })); }
public IActionResult DeleteWedding(int idWedding) { int? CurrentUser = HttpContext.Session.GetInt32("CurrentUser"); Weddings deleteWedding = _context.weddings.SingleOrDefault(x => x.idWedding == idWedding); _context.Remove(deleteWedding); _context.SaveChanges(); return(Redirect("/Dashboard")); }
public IActionResult CreateWedding(Weddings NewWedding) { if (ModelState.IsValid) { _context.Weddings.Add(NewWedding); _context.SaveChanges(); TempData["wedding_id"] = NewWedding.id; return(RedirectToAction("Rsvp")); } return(View("Plan")); }
public IActionResult Remove(int wedId) { if (ActiveUser == null) { return(RedirectToAction("Index", "Home")); } Weddings thisWedding = _context.weddings.SingleOrDefault(wed => wed.weddingId == wedId); _context.weddings.Remove(thisWedding); _context.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult Show(int wedId) { if (ActiveUser == null) { return(RedirectToAction("Index", "Home")); } Weddings weddingCouple = _context.weddings .Include(w => w.guests) .ThenInclude(guest => guest.Guest) .Where(wed => wed.weddingId == wedId).SingleOrDefault(); return(View(weddingCouple)); }
public IActionResult LeaveWedding(int WeddingId) { Atendees SelectedAtendeeObject = _context.Atendees.Where(w => w.WeddingsId == WeddingId && w.UserId == HttpContext.Session.GetInt32("CurrentUserId")).SingleOrDefault(); _context.Remove(SelectedAtendeeObject); // Get wedding object in order to decrement NumGuests Weddings SelectedWedding = _context.Weddings.Where(w => w.WeddingsId == WeddingId).SingleOrDefault(); SelectedWedding.NumGuests--; _context.SaveChanges(); return(RedirectToAction("Account")); }
public IActionResult MDelete(int id) { Weddings dwedding = _context.Weddings.SingleOrDefault(m => m.id == id); var parent = _context.Weddings.Include(x => x.Guest).SingleOrDefault(m => m.id == id); foreach (var guest in parent.Guest.ToList()) { _context.Guests.Remove(guest); } _context.Weddings.Remove(dwedding); _context.SaveChanges(); List <Weddings> data = _context.Weddings.Include(x => x.creator).Include(x => x.Guest).ThenInclude(y => y.Users).ToList(); ViewBag.weddings = data; return(View("Dashboard")); }
public IActionResult CreateWedding(Weddings newWedding) { if (loggedInUser == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { newWedding.UserId = loggedInUser.UserId; dbContext.Weddings.Add(newWedding); dbContext.SaveChanges(); return(RedirectToAction("Dashboard", "Wedding")); } return(View("Create")); }
public IActionResult Delete(int WeddingId) { int?CurrentUserId = HttpContext.Session.GetInt32("CurrentUserId"); // Get wedding if creds match Weddings SelectedWedding = _context.Weddings.Where(w => w.AdminId == (int)CurrentUserId && w.WeddingsId == WeddingId).SingleOrDefault(); if (SelectedWedding.Bride != SelectedWedding.Bride) { return(RedirectToAction("Login", "Home")); } else { _context.Weddings.Remove(SelectedWedding); _context.SaveChanges(); return(RedirectToAction("Account")); } }
public IActionResult SubmitNewWedding(WeddingsViewModel model) { if (ModelState.IsValid) { Weddings NewWedding = new Weddings { AdminId = (int)HttpContext.Session.GetInt32("CurrentUserId"), Bride = model.Bride, Groom = model.Groom, Address = model.Address, Date = model.Date, NumGuests = 0, CreatedAt = DateTime.Now, UpdatedAt = DateTime.Now, }; _context.Weddings.Add(NewWedding); _context.SaveChanges(); } return(RedirectToAction("Account")); }
public IActionResult Rsvp(int wedId) { if (ActiveUser == null) { return(RedirectToAction("Index", "Home")); } RSVP thisRsvp = new RSVP(); { Weddings selectedWedding = _context.weddings.SingleOrDefault(w => w.weddingId == wedId); thisRsvp.weddingId = selectedWedding.weddingId; thisRsvp.userId = ActiveUser.userId; thisRsvp.Guest = ActiveUser; thisRsvp.Wedding = selectedWedding; _context.rsvps.Add(thisRsvp); _context.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Create(ViewWedding newWed) { if (ActiveUser == null) { return(RedirectToAction("Index", "Home")); } if (ModelState.IsValid) { Weddings thisWedding = new Weddings { bride = newWed.bride, groom = newWed.groom, date = newWed.date, address = newWed.address, userId = ActiveUser.userId }; _context.weddings.Add(thisWedding); _context.SaveChanges(); return(RedirectToAction("Index")); } return(View("Planner")); }
public IActionResult CreateWedding(WeddingViewModel CreateWedding) { int? CurrentUser = HttpContext.Session.GetInt32("CurrentUser"); Users user = _context.Users.Where(x => x.idUser == CurrentUser).SingleOrDefault(); if (ModelState.IsValid) { Weddings NewWedding = new Weddings(); { NewWedding.Bride = CreateWedding.Bride; NewWedding.Groom = CreateWedding.Groom; NewWedding.Date = CreateWedding.Date; NewWedding.Address = CreateWedding.Address; NewWedding.host = user; NewWedding.CreatedAt = DateTime.Now; NewWedding.UpdatedAt = DateTime.Now; _context.Add(NewWedding); _context.SaveChanges(); return(RedirectToAction("WeddingProfile")); } } return(View()); }
// GET: Wedding public ActionResult Index() { string allPicturesLocation = "/Content/Images/wedding"; string frontPageHeader = ConfigurationManager.AppSettings["weddingMenuHeader"]; string frontPageText = ConfigurationManager.AppSettings["weddingMenuText"]; string weddingMenuDescription = ConfigurationManager.AppSettings["weddingMenuDescription"]; List <string> weddingCategories = ConfigurationManager.AppSettings["weddingCategories"].Split('|').ToList(); List <string> weddingNames = ConfigurationManager.AppSettings["weddingFoodNames"].Split('|').ToList(); List <string> weddingPictureNames = ConfigurationManager.AppSettings["weddingPictures"].Split('|').ToList(); List <string> weddingDescriptions = ConfigurationManager.AppSettings["weddingDescriptions"].Split('|').ToList(); List <WeddingPage> weddingCategoryDetails = new List <WeddingPage>(); for (int category = 0; category < weddingCategories.Count; category++) { List <food> weddingFoods = new List <food>(); List <string> categoryFoodNames = weddingNames[category].Split('\\').ToList(); List <string> categoryFileNames = weddingPictureNames[category].Split(',').ToList(); List <string> categoryFoodDescriptions = weddingDescriptions[category].Split('\\').ToList(); for (int file = 0; file < categoryFileNames.Count; file++) { categoryFileNames[file] = allPicturesLocation + "/" + categoryFileNames[file]; } var foodDetails = categoryFoodNames.Zip(categoryFileNames, (name, file) => new { Name = name, File = file, }) .Zip(categoryFoodDescriptions, (a, b) => new { Name = a.Name, File = a.File, Description = b, }); foreach (var weddingFood in foodDetails) { var foodDetail = new food { fileLocation = weddingFood.File, foodName = weddingFood.Name, description = weddingFood.Description }; weddingFoods.Add(foodDetail); } var weddingInfo = new WeddingPage { header = weddingCategories[category], foodOfCategory = weddingFoods }; weddingCategoryDetails.Add(weddingInfo); } Weddings weddingData = new Weddings(); weddingData.weddingPages = weddingCategoryDetails; weddingData.frontPageHeader = frontPageHeader; weddingData.frontPageText = frontPageText; weddingData.frontPageImage = allPicturesLocation + "/" + ConfigurationManager.AppSettings["weddingMenuImage"]; weddingData.frontPageImage2 = allPicturesLocation + "/" + ConfigurationManager.AppSettings["weddingMenuImage2"]; weddingData.weddingDescription = weddingMenuDescription.Split('|').ToList(); return(View(weddingData)); }