TW Prezentare 5.5
TW Prezentare 5.5
TW Prezentare 5.5
antohi.ionel@gmail.com
Introduction
How Did We Do?
Project Organization
GETTING Top Issues Facing In Visual Studio 2015-2017
STARTED Project References (NuGet Packages)
Project Configuration
First Run
In this course we'll provide an introduction to ASP.NET MVC by creating an
application that uses the Entity Framework and Entity Framework migrations to
read and update data in SQL Server, then deploy the application to a Windows
Server 2012 web site. We'll also drill into new features for version 4 of ASP.NET
Introduction MVC. We'll look at async controller actions and the new Task based programming
model, and build a Web API to consume with JavaScript and jQuery. The course
also covers the bundling and minification features included with the
System.Web.Optimization package, and the new mobile development features
including display modes and browser overrides.
SOLUTION SETUP
1. File > New > Project…
2. Other Project Types >
Visual Studio Solution
3. Give a project name.
Note:
We will use .NET
Framework 4.5
ADD PROJECT TO
SOLUTION
R-Click on Solution
ADD
NEW PROJECT…
WEB
PROJECT
1.Visual C#
2.Web
3.ASP.NET Web
Application (.NET
Framework)
Note
Save Solution name as
main namespaces ex:
eUseControl.[project
name]
PROJECT
TEMPLATES
PROJECT
TREE
Controllers - MVC
controllers are responsible
for responding to requests
made against an ASP.NET
MVC website. Each
browser request is
mapped to a particular
controller.
Views - A view is a
standard (X)HTML
document that can
contain scripts. You use
scripts to add dynamic
content to a view.
Models - In the ASP.NET
MVC framework, the
model is the part of the
application that is
responsible for the core
application or business
logic.
UPDATES
APP ROUTE
ASP.NET introduced Routing to
eliminate needs of mapping each
URL with a physical file. Routing
enable us to define URL pattern
that maps to the request handler.
This request handler can be a file
or class. In ASP.NET Webform
application, request handler
is .aspx file and in MVC, it is
Controller class and Action
method. For example,
http://domain/students can be
mapped to
http://domain/studentsinfo.aspx
in ASP.NET Webforms and the
same URL can be mapped to
Student Controller and Index
action method in MVC.
APP ROUTE
Route format:
Controller – is the same
as Class defined in
Controllers folder.
Action – is the Method
declared in Controller
Class.
Id – is additional
parameter.
ADD
CONTROLLER
The easiest way to create a
new controller is to right-
click the Controllers folder
in the Visual Studio
Solution Explorer window
and select the Add,
Controller menu option.
Selecting this menu option
opens the Add Controller
dialog.
ADD CONTROLLER
Notice that the first part of the
controller name is highlighted in the Add
Controller dialog. Every controller name
must end with the suffix Controller. For
example, you can create a controller
named HomeController but not a
controller named Home.
ADD
CONTROLLER
EDITING VIEW
https://docs.microsoft.com/en-us/aspnet/mvc/overview/
http://www.tutorialsteacher.com/mvc/asp.net-mvc-tutorials
REFS https://habrahabr.ru/post/175999/
https://habrahabr.ru/post/176001/
BOOTSTRAP
ASP.NET Design Integration
LUNA
ADMIN
THEME v1.3
LUNA Admin Theme is a premium admin theme with flat and dark design concept.
It is fully responsive admin theme built with latest Bootstrap 3+ Framework,
HTML5 and CSS3, Media query. It can be used for monitoring or administration
web applications, project management system, admin dashboard, application
backend or other custom project.
We are release continuous long term updates and many new features will be
ABOUT coming soon in the near future updates. Once you purchased LUNA, you will be
entitled to free download of all updates.
URL: https://wrapbootstrap.com/theme/luna-responsive-admin-theme-WB0J69TPB
Bootstrap: PerspectiveMockup: flowRouter:
http://getbootstrap.com/ http://www.pixeden.com/psd https://github.com/kadirahq/
-mock-up-templates/the-ne flow-router
jQuery: http://jquery.com/ w-macbook-psd-mockup
dataMaps:
jQueryUI: Roboto: http://datamaps.github.io/
http://jqueryui.com/ https://www.google.com/fon
ts/specimen/Roboto Switchery:
DataTables: http://abpetkov.github.io/swi
https://datatables.net/ Toastr: tchery/
https://github.com/CodeSev
Summernote:
REFS Flot:
http://www.flotcharts.org/
en/toastr
Timeline:
http://summernote.org/
Pace: http://codyhouse.co/gem/ver Bootstrap checkbox:
http://github.hubspot.com/p tical-timeline/ https://github.com/flatlogic/
ace/docs/welcome/ awesome-bootstrap-checkb
meteor: ox
Sparkline: https://www.meteor.com/
http://omnipotent.net/jquery Select2:
.sparkline/#s-about d3: http://d3js.org/ https://select2.github.io/
Nestable: moment: UI-select:
https://github.com/dbushell/ http://momentjs.com/ https://github.com/angular-u
Nestable i/ui-select
Typeahead:
https://github.com/bassjobse
CONFIG
<link rel="stylesheet" href="vendor/bootstrap/dist/css/bootstrap.css" />
<script src="vendor/bootstrap/dist/js/bootstrap.min.js"></script>
IMPLEMENTING
Call and define Class in Controller.
Set Data to the new defined Class.
Send new Object to View.
IMPLEMENTING
Define Model in View.
IMPLEMENTING
SHOW DATA?
Define a bootstrap Table.
Call Object referenced in
Model.
How to enumerate?
How to Show/Print string in
table body?
what @ ?
<%# %> <%@ %> is a Directive for ASP.NET Web Pages. Used for pages and
<%= %> controls to configure page/control compiler settings (<%@ Control
Inherits="MyParentControl" %>).
<%@ %> <%@ %> is also an Application Directive. Used to specify application-
specific settings for global.asax. Distinct from the page directives as it only
<%$ %>
uses a different tag set.
"special" <% %> is a Code Render Block (for inline code). One of 4 forms of
Embedded Code Blocks. Used for inclusion of server-side code to the
ASP.NET Render() method (<% x = x + 1; %>) of the generated class. Format:
single/multiline or multiple-linked (e.g. if/then/else interspersed with html)
tags but cannot be used to declare functions.
REF:
https://stackoverflow.com/questions/649428/asp-net-special-tags
https://stackoverflow.com/questions/14525811/asp-net-mvc-syntax
Username?
_Header
"BeginForm()" is an extension method that writes an opening "<form>" tag to the
response. "BeginForm()" is an extension method for both HtmlHelper and
AjaxHelper classes. It returns an MVCForm object from both HtmlHelper and
AjaxHelper class instances so there is not much difference but the AjaxHelper
method submits the form asynchronously using JavaScript.
There are two types of the BeginForm() extension methods, they are,
Post Data Html.BeginForm()
<> Ajax.BeginForm()
Controller
using (Html.BeginForm(“Action", “Controller", FormMethod.Post, new { autocomplete = "off" }))
{
//Html Form
}
IMPLEMENT
ACTION
VIEW
HTML – is BeginForm here?
Controller
REDIRECT
CONTROLLER
VIEW
HACK? O_o
Say QueryString again!
AJAX
JavaScript
A Data Model &
Business Layer
How to re-use components to make development more
intuitive?
By splitting the solution into 3 logical layers:
Presentation
Business logic
Objects
Note that for every domain object, we should have at least one model object.
The domain objects reside in the business logic layer. The model objects act as a sort
of bridge between the business logic layer and the actual data access layer.
All entities in a domain undergo some
sort of state transition. Initially they
have to be created, later on fetched,
modified and saved and at some point
State in time, deleted.
Entity Framework relies on every entity having a key value that it uses for tracking
entities. One of the conventions that code first depends on is how it implies which
property is the key in each of the code first classes. That convention is to look for a
property named “Id” or one that combines the class name and “Id”, such as “UserId”.
The property will map to a primary key column in the database.
EF
MODEL
[Required]
The MaxLength and MinLength attributes allow you to specify additional property
validations, just as you did with Required.
Here is the BloggerName with length requirements. The example also demonstrates
how to combine attributes.
EF
CONTEXT
An abstract function cannot have functionality. You're basically saying, any child class
MUST give their own version of this method, however it's too general to even try to
implement in the parent class.
A virtual function, is basically saying look, here's the functionality that may or may not
be good enough for the child class. So if it is good enough, use this method, if not,
then override me, and provide your own functionality.
WEB.
CONFIG
https://msdn.microsoft.com/en-us/library/
</connectionStrings> jj653752(v=vs.110).aspx
WEB.
CONFIG
MSSQ DB
@{
Layout =
"~/Views/Shared/_Layout_Blank.cshtml";
ViewBag.Title = "Login";
}
LOGIN
LOGIN
EF DB
EF http://www.entityframeworktutorial.net/entityframework6/introduction.aspx
FUNCTION http://www.entityframeworktutorial.net/querying-entity-graph-in-entity-framework.a
spx
Object Auto Mapping
AutoMapper
What is
AutoMapper?
AutoMapper is an object-object mapper. Object-object mapping works by
transforming an input object of one type into an output object of a different
type. What makes AutoMapper interesting is that it provides some
interesting conventions to take the dirty work out of figuring out how to
map type A to type B. As long as type B follows AutoMapper's established
convention, almost zero configuration is needed to map two types.
Mapping code is boring. Testing mapping code is even more boring.
AutoMapper provides simple configuration of types, as well as simple
Why use testing of mappings. The real question may be "why use object-object
AutoMapper? mapping?" Mapping can occur in many places in an application, but mostly
in the boundaries between layers, such as between the UI/Domain layers, or
Service/Domain layers. Concerns of one layer often conflict with concerns in
another, so object-object mapping leads to segregated models, where
concerns for each layer can affect only types in that layer.
USER INPUT
How to
Map Obj?
APP LOGIC
M1
Login
Controller
M2
Now let’s start with the default mapping. To do this you just map the classes
without adding any parameters. AutoMapper will automatically map properties
with the same name. So in this example that would be the Credential and
Password fields. This leaves the LoginIp, LoginDateTime field in ULoginData not
mapped as there is not an equivalent property in the UserLogin class.
The syntax for a mapping is Mapper.CreateMap<T1, T2>() using the proper types.
In this example T1 will be the UserLogin class and T2 will be the ULoginData class.
Below is a snippet with only using the default mapping.
https://security.stackexchange.com/questions/211/how-to-securely-hash-passwords
https://stackoverflow.com/questions/1054022/best-way-to-store-password-in-database
A user’s credentials are sent as a POST request to the server. The server authenticates the
user. If the credentials are valid, the server responds with a cookie, which is set on the user’s
browser and includes a SESSION ID to identify the user. The user sessions are stored in
memory either via files or in the database on the server.
https://ponyfoo.com/articles/json-web-tokens-vs-session-cookies
STORE
COOKIE
1. CookieGenerator
2. DB Validate Type
3. Store to DB
4. Return Cookie
GEN AES is an iterative rather than Feistel cipher.
<T> Filters Result Filters − Result filters contain logic that is executed before and
after a view result is executed. For example, you might want to modify a
view result right before the view is rendered to the browser.
Exception Filters − Exception filters are the last type of filter to run. You
can use an exception filter to handle errors raised by either your controller
actions or controller action results. You also can use exception filters to log
errors.
OnAction
Web API
Step #1
Step #2
Step #3
FIX $ RUN
Microsoft.AspNet.Mvc
Application_Start()
RouteConfig.RegisterRoutes(RouteTable.Routes);
API
Controller
GET
&
POST
TEST GET
TEST POST
FIRST
SELECT
Review of
Key What makes company unique
Objectives What makes company successful
Company
Financial
Review of Competitive
Prior Goals Progress
Summary of key financial results
Progress Revenue
Against
Profit
Key spending areas
Goals Headcount
Forecast vs. actual
Gross margin
Revenue Important trends
and Profit Compare company to rest of market
Use multiple slides to break out meaningful detail
Research and Development
Key Sales and Marketing