Category Archives: Uncategorized

Camel Case and Pascal Case

camel case – first letter of first word lower case, and first letter of every word, after that should be Upper Case

Examples:

  • camelCase
  • camelCaseLetter

pascal case – first letter of every word should be upper case

Examples:

  • CamelCase
  • CamelCaseLetter

I used to keep this in mind in  following way,

Camel has two humps, and first one smaller than second so like that , first word become lower case and others upper case

picture credits – https://targetstudy.com/nature/animals/camel.html

Advertisements

[NonStrongly Type] – Web API method Populate as @Html.DropDownList in ASP.NET MVC project’s Create/Edit view

Basic Class

public class Basic
{
    public int ID { get; set; }        
    public string NAME { get; set; }
}

Get Authers Id and Name Method

Business Logic

public IEnumerable<Basic> GetAuthersIdName()
{
     .....
}

So in Web API layer Controller Class I’m getting above details like below

URL

    // GET: api/Authers/all

    [System.Web.Http.Route("api/Authers/all")] 
    public IEnumerable<Basic> GetAuthersIdName()
    {
        return db.GetAuthersIdName();
    }

Then I can have following URL to fetch above details

http://localhost:13793/api/Authers/all

So In my MVC Layer , model folder I created a class to handle above details like below

public class LibraryClient
{
    private string AUTHER_URL = "http://localhost:13793/api/Authers";

    //DropDown

    public IEnumerable<Basic> GetAuthersIdName()
    {
        try
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(AUTHER_URL);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync("Authers/all").Result;
            if (response.IsSuccessStatusCode)
                return response.Content.ReadAsAsync<IEnumerable<Basic>>().Result;
            return null;
        }
        catch
        {
            return null;
        }

    }
}

Then I create Controller class to populate above details on front end like below

Controller Class

public class BooksController : Controller
{
    // GET: Books/Create
    public ActionResult Create()  
    {
        LibraryClient lc = new LibraryClient();
       //Method 1
       ViewBag.listAuthers = new SelectList(lc.GetAuthersIdName(), "ID", "NAME");
       //Method 2
       ViewBag.listAuthers = lc.GetAuthersIdName().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.NAME }); 
        return View("Create");
    }

    // POST: Books/Create
    [HttpPost]
    public ActionResult Create(Book book)
    {
        LibraryClient lc = new LibraryClient();
        lc.CreateBook(book);
        return RedirectToAction("BookswithAuthers", "BookWithAuther");
    }
}

View File

 @Html.LabelFor(model => model.Auther_Id, "Auther_Id", htmlAttributes: new { @class = "." })

@Html.DropDownList("Auther_Id", (IEnumerable)ViewBag.listAuthers, "---Select---", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Auther_Id, "", new { @class = "." }
</div>

[Strongly Type] – Web API method Populate as @Html.DropDownList in MVC project’s Create/Edit view

Base class that can populate list

using System.Web.Mvc;

namespace LibraryApp.Core.Entities
{
    public class Book
    {
        ...

        public IEnumerable<SelectListItem> Authers { get; set; }
    }
}

To get the System.Web.Mvc I have to install 'System.Web.Mvc.Extensions.Mvc.4'

Basic Class

public class Basic
{
    public int ID { get; set; }        
    public string NAME { get; set; }
}

Get Authers Id and Name Method

Business Logic

public IEnumerable<Basic> GetAuthersIdName()
{
     .....
}

So in Web API layer Controller Class I’m getting above details like below

URL

    // GET: api/Authers/all

    [System.Web.Http.Route("api/Authers/all")] 
    public IEnumerable<Basic> GetAuthersIdName()
    {
        return db.GetAuthersIdName();
    }

Then I can have following URL to fetch above details

http://localhost:13793/api/Authers/all

So In my MVC Layer , model folder I created a class to handle above details like below

public class LibraryClient
{
    private string AUTHER_URL = "http://localhost:13793/api/Authers";

    //DropDown

    public IEnumerable<Basic> GetAuthersIdName()
    {
        try
        {
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(AUTHER_URL);
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.GetAsync("Authers/all").Result;
            if (response.IsSuccessStatusCode)
                return response.Content.ReadAsAsync<IEnumerable<Basic>>().Result;
            return null;
        }
        catch
        {
            return null;
        }

    }
}

Then I create Controller class to populate above details on front end like below

Controller Class

public class BooksController : Controller
{
    // GET: Books/Create
    public ActionResult Create()  
    {
            Book model = new Book
            {
                //Method 1
                Authers = new SelectList(lc.GetAuthersIdName(), "ID", "NAME");
                //Method 2
                Authers = lc.GetAuthersIdName().Select(x => new SelectListItem { Value = x.ID.ToString(), Text = x.NAME })
            };
            return View(model);
    }

    // POST: Books/Create
    [HttpPost]
    public ActionResult Create(Book book)
    {
        LibraryClient lc = new LibraryClient();
        lc.CreateBook(book);
        return RedirectToAction("BookswithAuthers", "BookWithAuther");
    }
}

View File

 @Html.LabelFor(model => model.Auther_Id, "Auther_Id", htmlAttributes: new { @class = "." })

@Html.DropDownListFor(m => m.Auther_Id, Model.Authers, "---Select---", htmlAttributes: new { @class = "form-control" }) @Html.ValidationMessageFor(model => model.Auther_Id, "", new { @class = "." })
</div>

Defining a Class with Foreign Key in Entity Framework CodeFirst Approach

Introduction

This tip explains how to add a Foreign Key for a column in a model in Entity Framework code first approach with the help of Data Annotations.

Approach

We start with a simple scenario. We know every Book has an Author.

So we build our classes like below:

//Author Class
public class Author
{
       public int AuthorId { get; set; }

       public string AuthorName { get; set; }
}

 

//Book Class
public class Book
{
        public int BookId { get; set; }

        public string BookName { get; set; }

        public int AuthorId { get; set; }
}

And you want to create generate tables that consist of AuthorId foreign key in Book Table.

Like below:

sample9

To achieve the above task, you have to use Data Annotations and the following namespace in your classes:

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

So now your code needs to improve as shown below:

//Author Class
public class Author
{
        public Author()
        {

        }

        public int AuthorId { get; set; }

        public string AuthorName { get; set; }

        public ICollection<Book> Books { get; set; }
}
//Book Class
public class Book
{
        public Book()
        {

        }

        public int BookId { get; set; }

        public string BookName { get; set; }

        [ForeignKey("Author")]
        public int AuthorId { get; set; }

        public Author Author { get; set; }
}

Now you can easily generate two tables which are Book and Author with Foreign Key Constraint.

I found out valuable facts about world famous android OS

android-icon

From Rahul

1). It wasn’t Google’s idea: Android was the brainchild of Andy Rubin, who founded Android Inc. in October 2003 with the aim of creating a new mobile platform. Google later bought Android Inc. and hired Rubin and others in August 2005.

Andy Rubin
Andy Rubin

2). It almost didn’t work out: Android almost immediately ran out of cash after its founding, only to be saved, according to the Businessweek, by Steve Perlman.

Steve Perlman

3). The Nexus line was a hot rumour years before the Nexus One: People started predicting about the “gPhone” as early as 2007 though Nexus came out in 2010.

gPhone

4). Microsoft thought it would be a non-event: Microsoft’s Scott Horn, then head of the Windows Mobile marketing team, had told Engadget after Android’s release, “I don’t understand the impact they are going to have.”

Scott Horn
( A Former head of the Windows Mobile marketing team)

5). Resolution scaling was introduced in Version 1.6: The ability to automatically scale images based on display size appeared in Donut, or Android 1.6, paving the way for the huge range of device form factors on the Android market today.

Donut – Android 1.6

6). There’s an Android phone in space: A British firm launched a Nexus phone on Space, to control a satellite as part of an experiment and see how well consumer-grade electronics stand up to the rigors of space.

NASA sends another cheap Android-powered satellite in space, makes it dial home

 

7). Every app you run on your Android phone gets its own virtual machine: Each active app on an Android device runs in its own Dalvik VM, which keeps it safe and separate from core functions. This improves battery life and boosts performance of the phone.

The Android OS stack and Dalvik VM

 

The first official version code name was NOT a dessert: Google’s Dan Morrill confirmed in January that the very first alpha version of Android released to internal developers was R2-D2.

r2-d2

================================================