public async Task <IActionResult> EventCityFormResult(EventCityFormVM model) { // date time field -- getting rid of time -- coverting to string var tripDate = model.DateOfTrip.ToString("yyyy-MM-dd"); //Date of event -- Only will accetp a valid date -- only accepting numeric date Regex validDate = new Regex(@"^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"); // Adding Validation for tripDate -- official date form accepted only! if (validDate.IsMatch(tripDate)) { // taking the date adding one day, then converting to a string. var nextDay = model.DateOfTrip.AddDays(1).ToString("yyyy-MM-dd"); // this var contains all of the events for the date of the trip. var response = await _seatGeekClient.GetEventByCity(model.City, tripDate, nextDay); // view model set up EventCityFormResultV var viewModel = new EventCityFormResultVM(); var results = response.events; // mapping events from API response to the view model viewModel.Events = results .Select(results => new EventVM() { City = results.venue.city, Title = results.title, Id = results.id, VenueName = results.venue.name }) .ToList(); // mapping the trip to the TripParent table var eventHeader = new TripParentDAL(); eventHeader.City = model.City; eventHeader.UserId = _userManager.GetUserId(User); eventHeader.IsComplete = false; eventHeader.DateOfTrip = tripDate; // saving trip parent data _planFortDBContext.TripParent.Add(eventHeader); _planFortDBContext.SaveChanges(); viewModel.TripID = eventHeader.TripID; viewModel.DateOfTrip = tripDate; return(View(viewModel)); } else { // if date is not correct, action = EventCityForm // TIPPPPPP -- Action comes first.. Then Controller -- END TIPPPP return(RedirectToAction("EventCityForm", "Event")); } }
public async Task <IActionResult> EventCityFormResult(EventCityFormVM model) { var tripDate = model.DateOfTrip.ToString("yyyy-MM-dd"); Regex validDate = new Regex(@"^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$"); if (validDate.IsMatch(tripDate)) { var nextDay = model.DateOfTrip.AddDays(1).ToString("yyyy-MM-dd"); var response = await _seatGeekClient.GetEventByCity(model.City, tripDate, nextDay); var viewModel = new EventCityFormResultVM(); var results = response.events; viewModel.Events = results .Select(results => new EventVM() { City = results.venue.city, Title = results.title, Id = results.id, VenueName = results.venue.name }) .ToList(); var eventHeader = new TripParentDAL(); eventHeader.City = model.City; eventHeader.UserId = _userManager.GetUserId(User); eventHeader.IsComplete = false; eventHeader.DateOfTrip = tripDate; _planFortDBContext.TripParent.Add(eventHeader); _planFortDBContext.SaveChanges(); viewModel.TripID = eventHeader.TripID; viewModel.DateOfTrip = tripDate; return(View(viewModel)); } else { return(RedirectToAction("EventCityForm", "Event")); } }
public async Task <IActionResult> EventCityFormResult(EventCityFormVM model) { var response = await _seatGeekClient.GetEventByCity(model.City); var viewModel = new EventCityFormResultVM(); var results = response.events; viewModel.Events = results .Select(results => new EventVM() { City = results.venue.city, Title = results.title }) .ToList(); return(View(viewModel)); }