public IActionResult Submit(SubmittedCfp submittedCfp) { // TODO // Check validity if (ModelState.IsValid) { // Map var cfpToAddId = Guid.NewGuid(); var cfpToAdd = new Cfp { Id = cfpToAddId, EventName = submittedCfp.EventTitle, EventUrl = submittedCfp.EventUrl, EventImage = submittedCfp.EventImageUrl, EventDescription = submittedCfp.EventDescription, EventLocationName = submittedCfp.LocationName, EventLocationLat = submittedCfp.LocationLat, EventLocationLng = submittedCfp.LocationLng, CfpEndDate = submittedCfp.CfpEndDate, CfpAdded = DateTime.Now }; // Save CFP _cfpContext.Add(cfpToAdd); _cfpContext.SaveChanges(); // Post to Twitter // Send back ID to do whatever at the client-side return(Json(cfpToAddId)); } // Add invalid model return(BadRequest()); }
public async Task <IActionResult> Submit([FromForm] SubmittedCfp submittedCfp) { // TODO // Check validity if (ModelState.IsValid) { // Map var cfpToAddId = Guid.NewGuid(); var timezone = string.Empty; try { timezone = await GetTimezone(submittedCfp.LocationLat, submittedCfp.LocationLng); } catch { // Intentionally left blank, just for event to calendar // If it fails, sucks for you } var cfpToAddSlug = FriendlyUrlHelper.GetFriendlyTitle(submittedCfp.EventTitle); var i = 0; // Prevent duplicate slugs while (_cfpContext.Cfps.Any(cfp => cfp.Slug == cfpToAddSlug)) { cfpToAddSlug = $"{cfpToAddSlug}-{++i}"; } var cfpToAdd = new Cfp { Id = cfpToAddId, EventName = submittedCfp.EventTitle, EventUrl = submittedCfp.EventUrl, EventImage = ValidateImageUri(submittedCfp.EventImageUrl), EventDescription = submittedCfp.EventDescription, EventLocationName = submittedCfp.LocationName, EventLocationLat = submittedCfp.LocationLat, EventLocationLng = submittedCfp.LocationLng, CfpEndDate = submittedCfp.CfpEndDate.Date, CfpAdded = DateTime.Now, CfpUrl = submittedCfp.CfpUrl, EventStartDate = submittedCfp.EventStartDate?.Date ?? default(DateTime), EventEndDate = submittedCfp.EventEndDate?.Date ?? default(DateTime), ProvidesAccommodation = submittedCfp.ProvidesAccommodation, ProvidesTravelAssistance = submittedCfp.ProvidesTravelAssistance, SubmittedByName = submittedCfp.SubmittedByName, EventTwitterHandle = submittedCfp.EventTwitterHandle, EventTimezone = timezone, Slug = cfpToAddSlug, EventTags = submittedCfp.EventTags, CfpDecisionDate = submittedCfp.CfpDecisionDate?.Date ?? default(DateTime) }; // Save CFP _cfpContext.Add(cfpToAdd); await _cfpContext.SaveChangesAsync(); if (ShouldDownloadEventImageLocally()) { await _downloadEventImageMessageSender.Execute(cfpToAddId, submittedCfp.EventImageUrl); } // Post to Twitter account try { await PostNewCfpTweet(cfpToAdd); } catch { // Intentionally left blank, we can probably do something // more useful, but for now if Twitter fails ¯\_(ツ)_/¯ } // Send back ID to do whatever at the client-side return(Json(cfpToAddId)); } // Add invalid model return(BadRequest(submittedCfp)); }
public void AddCfp(Cfp cfpToAdd) { _cfpContext.Add(cfpToAdd); }