-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCourseNotes.txt
More file actions
47 lines (38 loc) · 2.17 KB
/
CourseNotes.txt
File metadata and controls
47 lines (38 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
NOTE: MVC Template from Microsoft COMES WITH BOOTSTRAP CSS LIBRARY
A)File Structure:
1. (Root)\Program.cs: Entry point to app.
2.
B)IActionResult: Interface encompassing result classes from actions done by the app. Could be formatted data or data indicating actions to take.
EX:
- ViewResult: Returns an HTML view
- JsonResult: Return JSON data
- ContentResult: Return plain text
- RedirectResult: Return response to redirect to URL
- RedirectToActionResult: Redirect to another ActionResult
- StatusCodeResult: Return response with given HTTP status code
C) Action Parameters
How actions (Methods defined in controllers) receive input. Can come from sources such as:
- Url segments defined in routes, ex: /Home/Index/{id?} route for "id" input. Input arg name MUST MATCH.
- Query strings such as in GET requests
- Form submissions
D) Entity Framework (Separate package)
Video also uses EntityFrameworkCore.Tools
NOTE: Since i don't have SQL Server installed, using PostgreSQL instead since i already have this installed
Interacting with database using dotnet objects, queries using c#
a) Code First
Define db with c# code
b) Database First (Scaffold)
Auto-generate models from existing db schema
Commands used during setup:
- dotnet new tool-manifest: Setup list of tools LOCAL to project (not solution)
- dotnet tool install dotnet-ef: Command line tools for EntityFrameworkCore
- dotnet ef migrations add *Name*: Add migration
- dotnet ef database update: Run migrations
- dotnet ef dbcontext scaffold *Database Connection String* *Database provider name*: Scaffold/Reverse engineer db schema found on said connection
c) Use async + Task return type for db operations
d) Razor:
@model: Data to pass to view from controller, strongly typed
ViewData: Dict containing data, loosely typed
e) Anchor tag helper with Razor: https://learn.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/built-in/anchor-tag-helper
NOTE: asp-for AUTOMATICALLY add's existing model's value to input elements
f) Model binding, to automatically bind values to a newly created Model instance as an argument to a controller's method