public ActionResult Edit([Bind(Include = "Id,Email,Status,InvitationId")] Invitee invitee) { if (ModelState.IsValid) { db.Entry(invitee).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } //ViewBag.InvitationId = new SelectList("accepted", "pending", "declined"); List <SelectListItem> items = new List <SelectListItem>(); items.Add(new SelectListItem { Text = "Accept", Value = "Accepted" }); items.Add(new SelectListItem { Text = "Not sure", Value = "Pending" }); items.Add(new SelectListItem { Text = "Decline", Value = "Declined" }); ViewBag.Status = items; return(View(invitee)); }
public ActionResult Edit([Bind(Include = "Id,LocationName,Description,Latitude,Longitude,Date, InviterId")] Location location) { if (string.IsNullOrEmpty(location.LocationName)) { ModelState.AddModelError("LocationName", "Tell us the location name."); } if (string.IsNullOrEmpty(location.Description)) { ModelState.AddModelError("Description", "Tell us what the event is."); } if (string.IsNullOrEmpty(location.Date.ToString())) { ModelState.AddModelError("Date", "Tell us when it is."); } if (string.IsNullOrEmpty(location.Latitude.ToString())) { ModelState.AddModelError("Latitude", "Tell us where it is."); } if (string.IsNullOrEmpty(location.Longitude.ToString())) { ModelState.AddModelError("Longitude", "Tell us where it is."); } if (DateTime.Compare(DateTime.Now, location.Date) > 0) { ModelState.AddModelError("Date", "You can't pick a date earlier than now."); } if (location.Latitude < -90 || location.Latitude > 90) { ModelState.AddModelError("Latitude", "Latitude should be in range of [-90,90]"); } if (location.Longitude < -180 || location.Longitude > 180) { ModelState.AddModelError("Longitude", "Longitude should be in range of [-180,180]"); } if (ModelState.IsValid) { db.Entry(location).State = EntityState.Modified; db.SaveChanges(); string sender = GetUserName(location.InviterId); string des = location.Description; foreach (Invitee invitee in location.Invitees) { // if (invitee.Status.Equals("Accepted")) // { try { String toEmail = invitee.Email; String subject = "An event's detail has changed!"; String contents = sender + "has changed event " + des + "'s detail. Check the link below!"; String link = Url.Action("Details", "Invitees", new { id = invitee.Id }, "https"); EmailSender es = new EmailSender(); es.Send(toEmail, subject, contents, link); } catch { return(RedirectToAction("Index", "Home")); } // } //else //{ // return RedirectToAction("Index", "Home"); //} } return(RedirectToAction("Index")); } return(View(location)); }