public IActionResult Create(SpeakerCreateViewModel viewModel) { if (!ModelState.IsValid) { // Something wasn't valid, send them back return(View(viewModel)); } var speaker = new User(); // Append on top the changes speaker.FirstName = viewModel.FirstName; speaker.LastName = viewModel.LastName; speaker.Username = GetUsername(); speaker.Bio = viewModel.Bio; speaker.Photo = viewModel.Photo; speaker.BlogUri = viewModel.BlogUri; speaker.TwitterHandle = viewModel.TwitterHandle; speaker.LinkedInProfile = viewModel.LinkedInProfile; speaker.FacebookProfile = viewModel.FacebookProfile; speaker.SpeakerInfo = new SpeakerInfo { Tagline = viewModel.Tagline }; // Actually save this model data! _speakerService.CreateSpeaker(speaker); // Redirect back to Index() return(RedirectToAction("Index")); }
public ActionResult Create(CreateSpeakerModel model) { if (ModelState.IsValid) { if (_speakerService.CreateSpeaker(model)) { return(RedirectToAction("List")); } } return(View()); }
public ActionResult <Speaker> Post([FromBody] Speaker speaker) { try { return(Ok(_speakerService.CreateSpeaker(speaker))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult Create(SpeakerViewModel model) { if (ModelState.IsValid) { Speakers newSpeaker = new Speakers(); newSpeaker.InjectFrom(model); var createSpeaker = speaker.CreateSpeaker(newSpeaker); if (createSpeaker == null) { ModelState.AddModelError("CompanyName", "Must be unique"); return(View(model)); } } return(RedirectToAction(nameof(Index))); }