public ServiceResult UpdateRSVP(RSVPViewModel rsvpVM) { ServiceResult result; bool esito = false; string message = "Errore imprevisto"; try { string lastGUID = rsvpVM.GUID; int lastId = rsvpVM.IdRsvp; DateTime now = DateTime.Now; RSVPServices services = new RSVPServices(); RSVP rsvp = rsvpVM.ToRSVPEntity(now); message = string.Empty; services.UpdateRSVP(rsvp, lastId, lastGUID); SendMails(rsvp); esito = true; message = "Operazione completata"; result = new ServiceResult(esito, message, rsvp.Guid); } catch (Exception exc) { message = exc.Message; esito = false; result = new ServiceResult(esito, message, exc); exc.WriteToLog(); } return(result); }
public ActionResult Create(RSVPViewModel model) { if (ModelState.IsValid) { var rSVP = model.ToRSVP(db); db.RSVPs.Add(rSVP); db.SaveChanges(); String myFood = ""; if (model.Attending == "yes") { foreach (int id in model.FoodMenuIDs) { var food = db.FoodMenus.Find(id); myFood += food.name + " "; } string msgBody = $@"Hello, {model.Name} registered for the reunion Food Items: {myFood} Total Guests: {model.GuestNumber} Allergies: {model.Allergies} Comments: {model.Comments}" ; string subject = "RSVP"; EmailSender.Send("*****@*****.**", subject, msgBody); return(RedirectToAction("RSVPYes", "RSVPs")); } else if (model.Attending == "no") { string msgBody = $@"Hello, {model.Name} isn't attending the reunion" ; string subject = "RSVP"; EmailSender.Send("*****@*****.**", subject, msgBody); return(RedirectToAction("RSVPNo", "RSVPs")); } else { string msgBody = $@"Hello, {model.Name} might be attending the reunion. Let's follow up in a week."; string subject = "RSVP"; EmailSender.Send("*****@*****.**", subject, msgBody); return(RedirectToAction("RSVPMaybe", "RSVPs")); } } if (model == null) { return(HttpNotFound()); } ViewBag.FoodMenuCategories = db.FoodCategories.ToDictionary(x => x, x => new MultiSelectList(x.FoodMenus, "id", "name")); ViewBag.AllFoodMenus = new MultiSelectList(db.FoodMenus, "id", "name"); return(View(model)); }
// GET: RSVPs/Create public ActionResult Create(string id) { ViewBag.FoodMenuCategories = db.FoodCategories.ToDictionary(x => x, x => new MultiSelectList(x.FoodMenus, "id", "name")); ViewBag.AllFoodMenus = new MultiSelectList(db.FoodMenus, "id", "name"); var invitation = new RSVPViewModel(); invitation.Name = id; return(View(invitation)); }
public RSVPViewModel GetRSVPByGUID(string guid) { RSVPViewModel rsvpViewMode; try { RSVPServices services = new RSVPServices(); RSVP rsvp = services.GetCurrentRSVPByGUID(guid); if (rsvp == null) { throw new Exception(string.Format("RSVP {0} non trovato.", guid)); } rsvpViewMode = RSVPViewModel.ToRSVPViewModel(rsvp); } catch (Exception exc) { exc.WriteToLog(); throw new Exception("Purtroppo il tuo RSVP non è stato trovato!"); } return(rsvpViewMode); }
public ActionResult Edit(RSVPViewModel model) { try { Services srv = new Services(); ServiceResult result = srv.UpdateRSVP(model); if (!result.Esito && result.Exception == null) { throw new Exception(result.Message); } else if (!result.Esito && result.Exception != null) { throw result.Exception; } return(RedirectToAction("Index", "Home")); } catch (Exception exc) { log.Error("Errore!", exc); exc.WriteToLog(); return(RedirectToAction("ErrorPage", "Home", exc.ToCompleteMessage())); } }
public async Task <JsonResult> GetViewModel([FromQuery] string ls) { var viewModel = new RSVPViewModel(); if (ModelState.IsValid) { if (User.Identity.IsAuthenticated) { var user = await _userManager.FindByNameAsync(User.Identity.Name); // Check if the user has RSVPd for the next class. // and if so get the user's record. var rsvp = await _rsvpRepo.GetSingleRSVPByUserIDAndDateForAsync( user.Id.ToString(), DateTime.Now.Next(DayOfWeek.Sunday) ); var nextClass = DateTime.Now.Next(DayOfWeek.Sunday); // If user is in list and the date is date of next class // set RSVP to true else set it to false if (rsvp != null && (rsvp.DateFor.Date == nextClass.Date)) { viewModel.RSVP = true; } else { viewModel.RSVP = false; } viewModel.PhoneNumber = user.PhoneNumber != null ? "true" : "false"; viewModel.FirstName = user.FullName.Split(" ")[0]; } return(Json(viewModel)); } _logger.LogError("Error sending viewModel"); return(Json(viewModel)); // return empty viewModel. }
public RSVPView() { InitializeComponent(); RSVPVM = new RSVPViewModel(); this.BindingContext = RSVPVM; }