Load Me ASP.NET MVC 5 AJAX

by

Load Me ASP.NET MVC 5 AJAX  

 

السلام عليكم ,

في المثال التالي سوف نحاول استخدام AJAX  مع ASP.NET MVC  , واظهار موشر مشغولية المعالج , في اثناء تنفيذ اي عمليه.

 

 public class EmployeeController : Controller    {        private readonly IEmployee _Employee;        public EmployeeController(IEmployee employee)        {            _Employee = employee;        }        // GET: Employee        public ActionResult Index()        {            return View();        }        [HttpGet]        public ActionResult GetEmployees()        {           return PartialView("_GetEmployees", _Employee.GetEmployee);        }    }

 

Index Pege :

 

@{    ViewBag.Title = "Index";}<link href="~/Content/loadme.css" rel="stylesheet" />@{    var options = new AjaxOptions()    {        UpdateTargetId = "DivContent",        InsertionMode = InsertionMode.Replace,        HttpMethod = "Get",        OnBegin = "onLoadBegin",        OnSuccess = "onLoadSuccess"    };}<br/>@Ajax.ActionLink("Employees", "GetEmployees", "Employee", options,new { @class = "btn btn-primary" })<hr/><div id="DivContent">    Your PartialView Will be here. </div><div id="divLoading" style="display:none">    <div class="loadmeRect">        <div class="loadmeRectChild loadmeRect1"></div>        <div class="loadmeRectChild loadmeRect2"></div>        <div class="loadmeRectChild loadmeRect3"></div>        <div class="loadmeRectChild loadmeRect4"></div>        <div class="loadmeRectChild loadmeRect5"></div>    </div>    <div class="loadme-mask"></div></div>

 

partial View

 

@model IEnumerable<TestLoadMeAjax.Models.Employee><p>    @Html.ActionLink("Create New", "Create")</p><table class="table">    <tr>        <th>            @Html.DisplayNameFor(model => model.Name)        </th>        <th>            @Html.DisplayNameFor(model => model.Gender)        </th>        <th>            @Html.DisplayNameFor(model => model.Salary)        </th>        <th></th>    </tr>@foreach (var item in Model) {    <tr>        <td>            @Html.DisplayFor(modelItem => item.Name)        </td>        <td>            @Html.DisplayFor(modelItem => item.Gender)        </td>        <td>            @Html.DisplayFor(modelItem => item.Salary)        </td>        <td>            @Html.ActionLink("Edit", "Edit", new { id = item.Id }, new { @class = "btn btn-warning" })|            @Html.ActionLink("Details", "Details", new { id=item.Id }, new { @class = "btn btn-warning" }) |            @Html.ActionLink("Delete", "Delete", new { id=item.Id }, new { @class = "btn btn-warning" })        </td>    </tr>}</table>

Code GitHub

 

 

Tuples C# 7

by

In order to return multiple values from a method in C#, we can use approaches like creating out parameters, creating a custom class with the required properties, or using tuples. 

 

However, in C# 7.0, we have the concept of tuples (quite similar to existing tuples), which can help in returning multiple values from a method.

 

Suppose we have a method, which will return the Department and Age of an employee, based on the EmployeeID. Using the old ways, we could have two out parameters for department and age, along with the EmployeeID, or create a custom class of an employee type and return the values or even use the existing tuple types. However, with new features, we can have a method with two return type values; i.e., int age and string department. The signature of the method would look, as shown below.

public static (int, string) GetEmployeeById(int employeeId)         {             int empAge = 32;             string dept = "HR";             return (empAge, dept);         }

After calling the method, we can access the return values, as shown below.

var employeeDetails = GetEmployeeById(21);  Console.Write("Age is: " + employeeDetails.Item1+ ", Department is:" + employeeDetails.Item2); 

The code does not seem to be too user friendly here, as we have to use the keywords Item1, Item2 etc. (similar to the existing tuples concept). However, we can change our method signature to include the use of names for the return values. Hence, the code will change to what is shown below.

public static (int age, string department) GetEmployeeById(int employeeId)           {               int empAge = 32;               string dept = "HR";               return (empAge, dept);           }  

Now, in order to access the elements, our code will change to what is shown below.

var employeeDetails = GetEmployeeById(21);    Console.Write("Age is: " + employeeDetails.age + ", Department is:" + employeeDetails.department);

this was about the concept of tuples in C# 7.0.

 

 

?Source :C#Corner,MSDN

C# 7 Local Functions

by

The concept of function within a function, like we normally do inside a class.

We will create a method GetName() .

The code will look like the following.

static void Main(string[] args)  {     Console.WriteLine("Name is: " + GetName());  }  public static string GetName()  {    return "Name";  }  

Next, we need to add more , will create Function called GetFullName() , will call 2 methods GetFName() and GetLName. 

This result will be added to the GetFullName() and the complete result will be returned.

 

The main point here is that if we create a public method to concate our string togather, it will be globally available. If we create a private method, the method will be available to other methods as well, which is not required. So, what we will do is create the method as a sub-method within the GetFullName function. This will be created like any other normal function. So, the code will look like the following.

namespace ConsoleApplication1  {      class Program      {          static void Main(string[] args)          {              Console.WriteLine("Full Name is: " + GetFullName());          }          public static string GetFullName()          {              var FullName= GetFName() + " " +GetLName();                return FullName;                          string GetFName()              {                  return "First Name";              }              string GetLName()              {                  return "Last Name";              }          }      }  

 we have created another two methods GetFName() and  GetLName() within a function to return FullName(). 

 

 

Onion Architecture in ASP.Net MVC ????? ??????

by

Core project

 

 

?????? ???????? , ?? ?????? ?????? ?? ???? ??????? , ?? ??????? ???? ??? ??? ?????? Web layer , Infrastructure layer , ????? ??? ??? ?????? .

 

 

?? ????? ?? ?????? ???????? core  ?? ???? ??? ?? ???? ???? .

?????? ?? ????? Core layer  ??? ?????? :

???? ???????? (Domain Entities)

?????? ?????????? ??????? (Repositories interfaces)

??? ?? ?? ???? ?? ?????? ??? ????? ?????? , ??? :

Reference of the ORM like LINQ to SQL or EF

  1. ORM like LINQ to SQL or EF
  2. ADO.NET libraries
  3. Entity Framework .

Create Entity

?????? , Entity  ????? ?????? BloodDonor entity class. .

 

?? ???? ????? ??? ?????? , ????? ????? , ??? ??? ???????? ??????? ?? ??? , ?? ???? ?????? ???? ?????? , ?????? ?? ???????  .

????? ???????? ??????? , ???? ??? ?? ????? ???? :

  1. System.ComponentModel.DataAnnotations
  2. Entity Framework fluent API.

??? ????????? ???????? , ???? ?????? . ?? ??? ???? ?????? ???????? ???? ?? ????? ?????? ??? EntityFramework , ??? ???? ??????? DataAnnotations  .

???????? DataAnnotations  ?? ?????? ?????? ?????? , ??? ????? .

System.ComponentModel.DataAnnotations

 

??? ????? BloodDonor entity class ?? DataAnnotations  .

?????? ??????? ????? ?????? ???????? ??????? repository interface

Repository interface

??? ???? ????? ?????????? repository  ,   ??? ?????????? ???? ?? ??????? ???? ?????? ?????? ???????? ??? ??????? ??? ?? ???? ???? .

?? ?????? ?????????? repository interface , ??? ??? ????? ?? ?????? ????? ???????? ???? ??????? .

 

??? ???????? ?? ????? ?? ??????? ?????????? ?? ?????? ,?????? ??????? ????? ???? ??????? infrastructure project .

Infrastructure project

 

?? ????? ?????? ??????? ,??? ???? ????? ???????? ???????? ???? ???????.

  1. Database operation
  2. Accessing outside service
  3. Accessing File systems

 

?????? ?? ???? ???????? ??????? ???? ?? ????? ?????? ???????. ??? ??????  Entity Framework ?????? ?????? ????? ????????. ??? ???? ??  Entity Framework code first .

 ???? ??? ????? ?????? ??????? ???????:

  1. Create the data context class
  2. Implement the repository class
  3. Create the database initializer class

??? ????? data context class , ??? ????? ???? Entity Framework , ?? Nuget Package Manager .

DataContext class
 

????? ?????? Data context class  .

 

Connection string

< connectionStrings >< add name = "BloodDonorContextConnectionString" connectionString = "Data Source= LocalDb)\v11.0;Initial Catalog=BloodDonors;Integrated Security=True;MultipleActiveResultSets=true" providerName = "System.Data.SqlClient" / >< /connectionStrings>

 

???? ......

 

Source:c-sharpcorner,debugmode

Onion Architecture in ASP.Net MVC ????? ?????

by

Onion Architecture in ASP.Net MVC

 

???? Onion Architecture ?

?? ??????? ??????? ??  ????? ????????? ?????? ?????? ????????? ???????? ?????????? ?? ????? ??????? ??? ????? ???????? ????????.  ?? ??????? ??? ??????? ???? ??? ?? ??? Jeffery Palermo ?? ?????? ?? ??? 2008

 

????? Onion Architecture

- ?? Onion Architecture  ??????? ????? ?????? ????? ??????? ???????? (Interface) .

- ?? ?????? ??? ??????? ???????? ??? ?????? ??? ????? ???????? ? Web Service  ????? ?? ??? ?? ??????? ????????.

- ???? ??????? ?? ???? ???????? ?? ???? UI  ?? ??? ?? ??????? ???????? .

- ??????? (Obj) ???? ???? ?????? ?? ??? ?? ??????? ????????.

- ???? ??????? ???????? ?? ????? ??? ????? ???????? ?? ???????? ??? .

- ?? ????? ?? ????? ??? ???? ?????? ??? ??????? ????????.

- ?????? (domain object)???? ?? ?????? ?? ?????? , ??????  ?????? ??? ?? ?? ????? ???????? ?????? ????? ????????.

- ?? ???????? ??? ?? ???? ??? ?????? ???????? , ?? ?????? ??????? ??????? ?? ????? ??? ??????? ???????? .

- ?? ??????? ?? ???? ???? ????? ??? ????? ??????? ???????? .

 

???? ???????

 

????? ?? ????? ???? ??????? . ??? ???? ?? ???????? ??????? ??????? :

  1. Core project (Class library)
  2. Infrastructure project (Class library)
  3. Web project (MVC project)

 

 Core Project

 ?????? ??? ?????? (domain entities) ????????? (repositories interfaces) .

Infrastructure project

???? ??????? ??? ????? ??? ?????? ???? ?? ??????? ???????? .

Web project

?????? ???????? ??? ????? ??? MVC Controllers  ?HTML  .

???? ??????? ??? ?? ???? ??? ????? ?????? :

???? ........

 

Source:c-sharpcorner,debugmode