Talent without working hard is nothing.
by

Image Uploader Using ASP.NET MVC 5

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

المقالة التالية سنشرح كيفية تركيب Image Uploader بستخدام التقنيات التالية 

 ASP.NET MVC and AJAX with SQL Server  .

 

الصوره التالية توضج , اضافة مجلد Upload الذي سيتم حفظ الصور داخله .

 

نقوم ايضا بانشاء SQLServer Database  , بالحقول التالية , التى بدورها ستخفظ مسار الصوره و حجمها على قاعد البيانات . 

 

 

 

 

Code GitHub

 

 

Read more..
On
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

 

 

Read more..
On
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

Read more..
On
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(). 

 

 

Read more..
On
by

Database initialize class

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

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

 

Repository class implementation

 

?????? ??????? ????? ???? ?????? ??????? ?? ???? ?????????? repository class , ????? ????? ??????? ??? ????? ???????? ??????? LINQ ??? Entity  .

?????? BloodDonorRepository  , ???? ?? ???? ??? ???? ?????? ??  IBloodDonorRepository interface

 

?????? ??????? ?? ?????????? , ??? ?????? LINQ to Entity  ?? ??? ???????? ?? ????? ???????? , ??? ???? ?????? ?????

a blood donor

 

  1. Create object of context class
  2. Use context.entiy.Add(entity)
  3. Use context.SaveChnages()

 

 

???? ?????? ????? ??? ????? ???? ?????????? ????????? ?? ??????? , ????? ??? ??? ????? ??? Build  ??????? , ??????? ?? ????? ????? .

 

Web Project 


??? ???? ?????? ????? MVC  , ???? ????? ??????? ?? ???????? ??????? Core and Interface  , ?? ?????? ??????? ??????? ??? ?????? .

  1. infrastructure project
  2. core project
  3. Entity Framework package

 

??? ????? ?? ??????? , ?? ???? Build ????? ?? ?? ?? ?? ???? .

?? ??????  New Controller  ?? Entity Framework  .??? ?????? ??????  BloodDonorsController  .

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

  1. BloodDonor class from the core project as the Model class
  2. BloodDonorContext class as the data context class from the Infrastructure project

Read more..
On