Python for the .NET developer Transcripts
Chapter: Web frameworks
Lecture: Exploring the ASP.NET Guitary
0:00 Before we start writing the Python
0:02 the Flask version of guitar, of course we have a C#
0:05 version, course they built you a C# version.
0:08 And why did I build it in?
0:09 Well, ASP.NET Core, of course.
0:11 So let's just quickly poke around this ASP.NET web app.
0:15 Maybe you're familiar with ASP.NET
0:18 but just because you're a C# developer doesn't
0:20 mean you've done web development over here.
0:22 So I'll try to give you a quick fly over
0:23 but again this is not the main focus.
0:25 The main focus is rebuilding the equivalent
0:28 pythonic web version the proper idomatic version
0:32 of the python web app.
0:34 But nonetheless let's understand where we're coming from.
0:36 So let's start with the controller that's probably
0:39 where you want to start with an MVC framework ASP.NET.
0:41 So this app turns out to be pretty simple.
0:45 We've got a little dependency injection thing that
0:47 we're actually kind of ignoring going on here
0:49 but then we have a couple of methods basically only
0:53 two action methods and then this Error method which
0:56 ideally we don't hit I guess, but maybe we will.
0:59 So this is the home view, that is
1:01 that's this view right here with the sort of landing page
1:05 and we will rock, that sort if thing.
1:08 And then we have the guitars
1:10 and over here we're using view models.
1:13 Really nice design pattern that I love.
1:15 We're going to create one of these view models and pass
1:18 it off to the view. Now, this is for the guitars and we're going to say the
1:22 style is either all or acoustic or it's electric, right?
1:26 That's the part here where we're looking the guitars
1:29 and we're switching between these three.
1:32 So we're pulling that out, it's being passed
1:34 its part of the URL right up here. guitars/acoustic.
1:38 So guitars, acoustic and it's being passed over here
1:42 going to the data base and filtering it.
1:45 So I guess a good place to go from there would be like here.
1:49 So here's our view model it has some
1:51 basically the input data, and then it has the guitars.
1:54 We have a CatalogService like our guitar catalog I guess.
1:58 And it can go and get all the guitars based on style.
2:02 Let's go check that out.
2:04 Now here we have our turns a guitar array pass in a shop
2:08 style could be empty, like I said this is static data for
2:11 now it's going to be in the database soon.
2:14 If there's no filter just give all
2:16 otherwise we're going to do a link to objects query for now.
2:19 This is going to be a LINQ to Entity Framework later.
2:23 Going to say give me all the guitars with the style
2:25 such and such give me that guitar back.
2:27 And I guess the last major thing to look at is just
2:30 the views down here to round it out let me stop it so
2:35 you can get this out of the way.
2:38 When we go to our controller here and we call the
2:41 guitar method with the right stuff and we say return
2:43 view with this view model.
2:44 What it does is it goes to this Razor template over here.
2:47 And this Razor template of course shares this overall
2:51 layout that we're using.
2:53 So what we're going to do is we're going to say that view
2:55 model is this that we come in statically programing
2:59 gets it. Our little top bit this is just a padding for the linment
3:03 of around the navigation.
3:04 We have our custom guitars and these are the buttons.
3:08 So if we were over here those are the buttons you
3:10 can click there, and then for each guitar we're going to
3:14 spit out a little div that we're going to float, not float
3:17 we're going to put as an inline block and it has an
3:20 image which is the guitar image, the guitar name
3:22 and the guitar price.
3:24 That's it. That's right here the image, the name
3:28 and the price. I guess you could probably use a dollar
3:31 sign, something like that right there.
3:34 Not really required but we'll go ahead and throw it
3:38 in there for the future.
3:39 And that more or less is the web application, round one.
3:42 Later when we get to doing something more impressive
3:46 with the database, but for now this is the web app
3:49 that we're starting from in C# and we're going to
3:52 rebuild in Python and Flask.