GithubHelp home page GithubHelp logo

odetofood's Introduction

OdeToFood

A repo for the ASP.NET Core Pluralsight Project.

The following are additional notes and FAQs about the course.

ASP.NET Core 3

The original version of the code as recorded in the Pluralsight course is with ASP.NET Core 2.1. I've placed this code into a branch named aspnet21.

The master branch I am updating to use ASP.NET Core 3 and the latest versions of Bootstrap and jQuery.

Module 2 (Drilling into Data)

Clip 2 (Creating the New Project)

To create, build, and run a project like we do in Visual Studio, you can use the command line:

dotnet new razor
dotnet build
dotnet run

Some environments, like Visual Studio Code, can also detect .NET Core projects and automatically add support to build and run from the VS Code menus.

Clip 3 (Editing Razor Pages)

VS uses some magic to automatically restart the web server when you make changes to source code files. If you are using command line tools, you can do the same using:

dotnet watch run

... instead of ...

dotnet run

Clip 7 - (Creating an Entity)

You can use dotnet to create the class library. Place this at the same folder level as the OdeToFood project.

dotnet new classlib

Module 3 (Working with Models and Model Binding)

Clip 3 (Building a Search Form)

Bootstrap 4 changed some classes and no longer includes glyphicons. Font Awesome is a good replacement. Once you've included the Font Awesome stylesheet into your _Layout page with a link tag, the icons are just as easy to use. To show a search icon use this code:

<input type="search" class="form-control" value="" />
<div class="input-group-append">
    <button class="btn btn-secondary">
        <i class="fas fa-search"></i>
    </button>
</div>

Module 4 (Editing Data with Razor Pages)

Note that Bootstrap version 4 no longer provides icons out of the box. See the docs for more info. Font Awesome is a good replacement.

Clip 5 (Adding Validation Checks)

You'll need to install the NuGet package dotnet-aspnet-codegenerator. Install this package as a tool From the comamnd line, and also install the design package for the project:

dotnet tool install --global dotnet-aspnet-codegenerator 
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

After installing, the following command should display a help screen and a list of available generators. Make sure you execute the command inside a directory where a project exists.

dotnet aspnet-codegenerator -h

Now you should be able to follow along with the scaffolding in the video.

dotnet aspnet-codegenerator razorpage List Empty -udl -outDir Pages\Restaurants\

For Visual Studio users, you might also want a reference to CodeGeneration tools you can use from the UI. Run the following command in the project directory:

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet restore

This will allow you to right-click the project and run scaffolding. s

Module 5 (Working with SQL Server and the Entity Framework Core)

Clip 2 (Installing the Entity Framework)

See Install SQL Server on a Mac if you are moving through the course using Visual Studio for the MAC. From user db:

Once installed, take a note of your database user name (usually 'sa') and password.

It is very smooth. I am using DBBeaver which is also explained in the article above and I find it great.

Following Scott's class here, where he sets database connection string in appsettings.json to his local DB instance in Windows, you can just use this connection string:

"ConnectionStrings": {
    "OdeToFoodDb":"Server=localhost,1433;Database=OdeToFood;User Id=sa; Password=your-password"
}

, then replace 'your-password' with your real password you choose when installing the SQL server image in docker container.

It is very simple and smooth experience.

Clip 4 (Using the Entity Framework Tools)

Starting in 3.0, the dotnet ef command-line tool is no longer included in the .NET Core SDK. Before you can execute EF Core migration or scaffolding commands, you’ll have to install this package as either a global or local tool. To install the latest version as a global tool, use the following command:

dotnet tool install --global dotnet-ef

Module 7 (Integrating Client-side JavaScript and CSS)

Implementing an API Controller

If you aren't using Visual Studio, the scaffolding shown in this clip is something you can also achieve with the dotnet-aspnet-codegenerator tool discussed in module 3. The command would look like:

dotnet aspnet-codegenerator controller -api -name RestaurantsController
    --model OdeToFood.Core.Restaurant --dataContext OdeToFood.Data.OdeToFoodDbContext 

Note the -api switch uses a single dash.

Changes to routing and services

In ASP.NET Core 3.0+, you can bring in fine grained services to support Razor pages and controllers. You don't need to bring in the entire MVC framework. To use Razor pages and API controllers, for example, you'd need to have the following two method calls inside the ConfigureServices method of Startup.cs.

// for aspnetcore3.0+

services.AddRazorPages();
services.AddControllers();

Routing is also a bit different, and more granular in 3.0. You'll need to the following code at the bottom of the Configure method in Startup.cs for 3.x:

app.UseRouting();            
app.UseEndpoints(e =>
{
    e.MapRazorPages();
    e.MapControllers();
});

odetofood's People

Contributors

ameyer117 avatar berkansasmaz avatar davidecastronovo avatar dependabot[bot] avatar emw-ghertner avatar gabrielizalo avatar odetocode avatar ulfvins avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odetofood's Issues

Following readme: aspnet-codegenerator has no generators

In Module 3 of the Readme.md, I installed aspnet-codegenerator per instructions: dotnet tool install --global dotnet-aspnet-codegenerator.
Then tried to use razorpage generator, and command window says

No code generators are available in this project. Please add the 'Micrososft.VisualStudio.Web.CodeGeneration.Design' NuGet packate to the project. Pleas add Micrososoft.VisualStudio.CodeGeneration.Design package to the project as a NuGet package reference.

Maybe there is a step missing in your instructions in Module 3 of your Readme.md to add the missing Nuget package.

Clarity: Ambiguous video makes it appear that model binding fails.

PROBLEM:

While doing the model binding for the Details page, the Name, Cuisine, and Location data never populate.

URL:

Link to Course ASP.NET Fundamentals, Module 3, Clip 8: "Linking to the Details"

Timestamp:

5:52

Expected:

And now I have my little zoom in icon on the right, and if I click on this, I can see yes, that went to /Restaurants/Detail query string restaurantId=2. So my tag helpers asp-page and asp-route, they decided the best way to pass a restaurant ID to the Detail page is by placing the restaurant ID in the query string.

I expect to see the Name as a header, Id, Location, and Cuisine related to the Id parameter passed in.

Actual (May 08, 2019 at 3:14 pm EDT):

The Id comes in, but the Name, Location, and Cuisine do not. The intellisense doesn't notice anything wrong, and in fact suggests the Location field.

The lack of name and location data is both in my code, in this video, and the next video.

Possible causes:

I believe this is because we create a new Restaurant, but never assign values to the other fields.

Suggested Fix:

Update the videos where you reassign the values.
Or provide a brief voice-over mentioning those fields are not yet bound and will be addressed later in the course.
Your final source code below shows you update this later, so personally I would find this helpful to mention as I spent some time attempting to debug before I discovered the issue: https://github.com/OdeToCode/OdeToFood/blob/master/OdeToFood/OdeToFood/Pages/Restaurants/Detail.cshtml.cs

Bootstrap 4 no longer has input-group-btn

In the tutorial & even after your .NET Core 3 update, the span tag in List.cshtml uses the bootstrap tag input-group-btn <span class="input-group-btn">

Per the documentation from Bootstrap:

Input groups

Input group addons are now specific to their placement relative to an input. We’ve dropped .input-group-addon and .input-group-btn for two new classes, .input-group-prepend and .input-group-append. You must explicitly use an append or a prepend now, simplifying much of our CSS. Within an append or prepend, place your buttons as they would exist anywhere else, but wrap text in .input-group-text.

Validation styles are now supported, as are multiple inputs (though you can only validate one input per group).

Sizing classes must be on the parent .input-group and not the individual form elements.

Can't able to scaffold Api controller

I'm following the Pluralsight course and I'm currently stopped at this point. When I want to create Api controller for restaurant, I'm getting the error blow. Can someone help with this issue?

image

ReadMe is missing instructions for ASP.NET Code Generator

PROBLEM:

README.md file is missing instructions.

URL:

Link to Course ASP.NET Fundamentals, Module 3, Clip 5: "Using the Scaffolding Tools"

Timestamp:

0:34

Expected:

This is done using a tool, which is the dotnet aspnet-codegenerator. In the README file of the OdeToFood GitHub repository, I have placed some instructions on how you can install this tool. I just want to run it here to show you that you can use this tool to run a generator. There's several generators available, for areas, for controllers, for identity. The one we're using is the one for Razor Pages.

Actual (May 08, 2019 at 10:00 am EDT):

https://github.com/OdeToCode/OdeToFood#odetofood

Suggested Fix:

Provide instructions and/or link to proper tool and 3rd-party instructions from Microsoft.

Example:

You will be installing the Nuget Package:
dotnet-aspnet-codegenerator

Although Microsoft's guide is in regard to Microsoft Identity, the steps for installing the code generator apply. You can follow Microsoft's instructions for installing this code via the command line from their guide on Scaffold Identity.

I have reproduced the steps below:

  1. If you have not previously installed the ASP.NET Core scaffolder, install it now:
    dotnet tool install -g dotnet-aspnet-codegenerator
  2. Add a package reference to Microsoft.VisualStudio.Web.CodeGeneration.Design to the project (*.csproj) file. Run the following command in the project directory:
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet restore

Bootstrap 4 no longer has btn-default

In the tutorial & even after your .NET Core 3 update, the button tag in List.cshtml uses the bootstrap tag btn-default

Unfortunately, there doesn't seem to be an exact replacement, but per stackoverflow the closest equivalent seems to be btn-outline-secondary

value of input field does not change when back button is pressed

The problem is that when i'm pressing back button in chrome the value of input field is changed in inspector but the value is not changed in browser window. This does not happen in edge i dont know why.

here you can see that the value in inspector and browser are different.
Untitled
here is the code. I checked in this project too but this project too have this problem.
Screenshot (99)
Screenshot (100)

Secion 8 : Building a custom middleware needs updating for NET6

The method generated in this section in ASP.NET 6 is a Task

app.Use(SayHelloMiddleWare);
  
  Task SayHelloMiddleWare(HttpContext arg1, Func<Task> arg2) {}

This may need some clearing up for future use
I understand this is not the purpose of this lesson but it might trip up some that come accross it,

error code CS0246

Hi, I'm getting the following error:

  • The type or namespace name 'IRestaurantData' could not be found (are you missing a using directive or an assembly reference?)
  • Startup.cs

Editing the In memory data is not working

After I applied what is in Module 4, clip 4, I can see the new restaurant name in the edit page, however when I go to the list page I don't see the new name.

I tried to debug to see what is happening, as long as I stay in the edit pagenthe data in memory is changed, but when I go to other pages the InMemoryRestaurantData Class constructor is called therefore we go back to the initial values

My question here, is this behavior normal? every time I call a page it will re initialize all the objects in it?

Should I continue to the next clip or what, I'm confused...

default view component doesn't link correctly +

I'm at a loss, following tutorial (ASP.NET Core Fundamentals part 6) - step by step and have several issues.
1.) footer covers over the generated cards in /Lists
2.) The footer with a total number of restaurants generated in a default view component and a link to Lists - doesn't actually link where it's supposed to but instead to whatever page you're currently on instead.

The only difference in code is using class 'card' instead of 'well' and 'Panel' as BS5 no longer supports those.

Module 7: You seem awfully certain Visual Studio users have npm installed

You spent a lot of time telling us how to install datatables.net via npm and simply assumed that we have npm. I'm using Visual Studio 2019, I have that node.js editing option installed, and even the command line console via Visual Studio has no clue what npm is.

I'm probably going to spend time trying to figure out a different way to install datatables.net, but I'm not going to bother with npm.

The way I see it, if the course isn't about npm, and the instructor never bothered to make sure that we knew how to get our hands on npm, and the course is marketed to beginners, then npm isn't of any importance to said course.

Error Code CS0311

Also getting this:

  • The type 'OdeToFood.InMemoryRestuarantData' cannot be used as type parameter 'TImplementation' in the generic type or method 'ServiceCollectionServiceExtensions.AddSingleton<TService, TImplementation>(IServiceCollection)'. There is no implicit reference conversion from 'OdeToFood.InMemoryRestuarantData' to 'IRestaurantData'.
  • Startup.cs 27 Active

Typo

In section #8, clip #3 (Processing Summer Corn...), Middleware is misspelled as Middlewear.

Typo: Backslash vs Forward Slash in List.cshtml

Noticed in the video & current code, when you reference the Edit page on the Add New button, your slash is a backslash, where everywhere else in the code it's a forward slash. It actually still works fine, probably through ASP.NET magic, but thought I'd mention it for consistency.

<a asp-page=".\Edit" class="btn btn-primary">Add New</a>

How to run this in VS Code?

Is the README.md meant for use in VS Code?

What are the sequence of steps needed? I suppose the repo is the version as at the end of the complete course? I am still at Module 4.

I cloned the repo and pressed F5. The build was successful, but then it ran into bin\Debug\n...\OdeToFood.dll does not exist.

I then tried the first of the three steps shown for Clip 2, dotnet new razor, and Git shows 51 files changed. However, I couldn't find what actually changed, as git diff shows that the previous versions are all blank files. I am a bit puzzled by this.

What is the proper way to make use of the repo? Thanks.

Using TempData - Cookie Policy options.

When following the course I was having an issue passing data into TempData.
This caused an issue when trying to display the "Restaurant saved!" alert on the details page.

Root cause was that by default the Cookie Policy Options are set to need consent. Could be because I am in Europe.

Changed to false in Startup.cs and the issue was resolved.

CS0579 - Duplicate 'System.Reflection.Assembly[something]Attribute Errors

Hi Scott,

I'm enjoying the instruction, but I must have missed an instruction, or "fixed" something I should not have fixed along the way through your ASP.Net Core lesson, but I've run upon this CS0579 error twice now getting up to section 3.8 "linking to the details."

The first time I ran into this error, I was able to add a series of "false" <GenerateAssembly[something]Attribute> statements to the .csproj file and the duplication error cleared itself. The errors started popping up again around section 3.8 and even though I back out of the changes for several modules, I keep getting the error.

Originally I thought the problem was caused because I created the OdeToFood project with the target framework of ".Net Core 2.1" and then failed to do the same for the "OdeToFood.Core" and "OdeToFood.Data" projects. And I switched all three to 2.1, and then to 3.1 trying to see if there was some reason why the compiler is trying to build these assemblies multiple times. Setting the "generate" flags to false for all of them in each .csproj file doesn't seem to eliminate the errors either.

I'm just going to archive the solution and start over again and not try to be clever by using 2.1, and follow the added instructions for 3.0+ here on github. But, I figured I would pass this along in case others were having the same problem.

Good Fortune,
Richard

VS4Mac Notes

Video titled "Creating the New Project" talks about notes for VS4Mac users in the repo but I am finding none. Is this course adequate for VS4Mac users?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.