Project Questions
Project Questions
ComponentModel;
2. Key,Required,Datatype,DisplayFormat: using System.ComponentModel.DataAnnotations;
3. Column,DatabaseGenerated: using System.ComponentModel.DataAnnotations.Schema;
4. DbContext,DbSet: public object users { get; internal set; }
5. <IEnumerable<admin>:using System.Collections.Generic;
6. Task: using System.Threading.Tasks;
7. FirstOrDefaultAsync, ToListAsync,EntityState: using System.Data.Entity;
8. Httpclint: using System.Net.Http;
9. [HttpPost, ValidateAntiForgeryToken, ValidateInput(true)],ActionResult: using System.Web.Mvc;
HttpClient
we will use HttpClient class in console application to send data to and receive data from Web
API which is hosted on local IIS web server.
Every time something calls this method, the caller has to wait up to 1 minute before it can
resume processing. That's a minute of wasted time, time it could be spending doing other tasks.
1. We marked the method as async. This tells the compiler that this method can run asynchronously.
2. We used the await keyword on the nameTask variable. This tells the compiler that we will
ultimately need the result of the GetLongRunningName() method, but we don't need to block on that
call.
3. We changed the return type to Task<string>. This informs the caller method that the return type
will eventually be string, but not right away and that can do other things
while GetLongRunningName() is processing.
Task<T>: This class represents an asynchronous operation that returns a value, and can be
awaited.
The async keyword turns a method into an async method, which allows you to use the await keyword in
its body. When the await keyword is applied, it suspends the calling method and yields control back to
its caller until the awaited task is complete. await can only be used inside an async method.
ModelState
A ModelState is a collection of name al value pairs submitted to the server duri POST request. It also
contains a collect error messages for each value. The Modelstate represents validation errors submitted
HTML form values.
HttpClient Class
Namespace: System.Net.Http
Provides a class for sending HTTP requests and receiving HTTP responses from a resource identified by a
URI.
What is ValidateAntiForgeryToken?
They allow you to write promise-based code as if it were synchronous, but without blocking the main
thread. They make your asynchronous code less "clever" and more readable. If you use the async
keyword before a function definition, you can then use await within the function. 12-Feb-2019
What is async task in C#?
In LINQ, AsQueryable operator / method is used to convert given input list elements to IQueryable<T>
list and AsQueryable is a method of System.
Enumerable.Empty<TResult> Method
Namespace:System.Linq
Returns an empty IEnumerable<T> that has the specified type argument.
Bind Attribute
ASP.NET MVC framework also enables you to specify which properties of a model class you want to
bind. The [Bind] attribute will let you specify the exact properties of a model should include or exclude
in binding.
What is bind attribute in MVC?
When we have an ASP.NET MVC View that accepts user input and posts those inputs to a server we have
the option to use the built-in Model-binding features to provide more control and security, We can
restrict the properties that are allowed to be bound automatically.
The [FromUri] attribute is prefixed to the parameter to specify that the value should be read from the
URI of the request, and the [FromBody] attribute is used to specify that the value should be read from
the body of the request. ... This is the default behavior of Web API.
AntiForgeryToken Method (System. Web. Mvc) Generates a hidden form field (anti-forgery token) that
is validated when the form is submitted.
BeginForm extension method in ASP.NET MVC5. ActionMethod – It defines which action method is look
for when submit button is clicked. ControllerName – It defines, which controller keeps the defined
action method. Get/Post Method – it defines the method you want to use to send data from form to
controller.
The [TestFixture] attribute at the beginning indicates that this class is a test fixture so that NUnit can
identify it as a runnable test class. ... SetUp method is run at the start of test fixture and TearDown
method is run at the end, after running all the test cases in the test fixture.
Setup
This attribute is used inside a TestFixture to provide a common set of functions that are performed just
before each test method is called. SetUp methods may be either static or instance methods and you
may define more than one of them in a fixture.