Created
March 27, 2019 04:40
-
-
Save sainture/9e768e1b58ccdc7a19c4066942897198 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // first create a Controllers folder | |
| // basic example of a controller and its actions | |
| using Microsoft.AspNetCore.Mvc; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Threading.Tasks; | |
| namespace WebApplication1.Controllers | |
| { | |
| public class ConferenceController: Controller | |
| { | |
| private readonly IConferenceService conferenceService; | |
| // constructor | |
| public ConferenceController(IConferenceService conferenceService) | |
| { | |
| // dependency injection is similar to Angular except here you need to declare service reference as a private property | |
| this.conferenceService = conferenceService; | |
| } | |
| public async Task<IActionResult> Index() | |
| { | |
| ViewBag.Title = "Conference Overview"; | |
| return View(await conferenceService.GetAll()); | |
| } | |
| public IActionResult Add() | |
| { | |
| ViewBag.Title = "Add Conference"; | |
| return View(new ConferenceModel()); | |
| } | |
| [HttpPost] | |
| public async Task<IActionResult> Add(ConferenceModel model) | |
| { | |
| if (ModelState.IsValid) | |
| await conferenceService.Add(model); | |
| return RedirectToAction("Index"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment