Tuesday 16 March 2021

C# Concepts

 Q1)What is Difference between  For Loop and For-Each Loop in C#?

  • For loop iterates a statement or a block of statements repeatedly until a specified expression evaluates to false.
  •  For-each loop is used to iterate through the items in object collections, List generic collections or array list collections. 
  • Performance: For Loops are faster than For-each Loop. If we iterate array list or any collection with for loop and for-each loop then you will find time consumed by a for-each loop is much more than for loop so For loops are faster than For-each loop.
Q2) What is mean by Conditional statement? 
Ans: A block of code that gets executed basis on a condition is known as conditional Statement. These are of two types:
  •  Conditional Branching
  •  Conditional Looping.
Q3)What is mean by Conditional Branching? 
Ans: These statements allow us to branch our code depending on whether certain condition was met or not. C# has two constructs for branching code
  •  If 
  • Switch
Q4)What is mean by Conditional Looping?
Ans: C# provides three different loops that allows us to execute a block of code repeatedly until a certain condition is met, those are 
  • For Loop 
  • While Loop 
  • Do While Loop
 Every Loop requires three things in common. 
  1. Initialization: That sets the starting point of the loop. 
  2. Condition: That sets the ending point of the loop. 
  3. Iteration: Which takes you to the next level of the cycle either forward or backward direction.
Q5)

Monday 15 March 2021

 What is Angularjs ?

What is AngularJS

 AngularJS looks like a JavaScript framework, but it's more than that. It's based on a Model-View-Controller framework. It's a framework with a purpose.  AngularJS helps developers in maintaining web infrastructures with ease & comfortability. It's built on the MVC architecture which commonly used for designing rich internet applications. The frameworks follow basic HTML & offer extension (in the form of directives) which has the capability to make the web site truly responsive & dynamic. It can automatically synchronize with models & views making AngularJS development an easy process. It follows the DOM methodology which focuses primarily on improvising testability & performance. 

So in short, Angular JS’s features are – Two-way data binding, templates, MVC structure, dependency injections, directives & testing features. Angular has the following key features which make it one of the powerful frameworks in the market. 

MVC – The framework is built on the famous concept of MVC (Model-View-Controller). This is a design pattern used in all modern day web applications. This pattern is based on splitting the business logic layer, the data layer, and presentation layer into separate sections. The division into different sections is done so that each one could be managed more easily. 

Data Model Binding – We don't need to write special code to bind data to the HTML controls. This can be done by Angular by just adding a few snippets of code. 

Writing less code – When carrying out DOM manipulation a lot of JavaScript was required to be written to design any application. But with Angular, you will be amazed at the lesser amount of code you need to write for DOM manipulation. 

Unit Testing ready – The designers at Google not only developed Angular but also developed a testing framework called "Karma" which helps in designing unit tests for AngularJS applications.

Saturday 13 March 2021

C# Program to Get a Number and Display the Sum of the Digits

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Program

{

    class Program

    {

        static void Main(string[] args)

        {

            int num, sum = 0, r;

            Console.WriteLine("Enter a Number : ");

            num = int.Parse(Console.ReadLine());

            while (num != 0)

            {

                r = num % 10;

                num = num / 10;

                sum = sum + r;

            }

            Console.WriteLine("Sum of Digits of the Number : "+sum);

            Console.ReadLine();

 

        }

    }

}

C# Program to Print a BinaryTriangle

 using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace Program

{

    class Program

    {

        public static void Main(String[] args)

        {

            int p, lastInt = 0, input;

            Console.WriteLine("Enter the Number of Rows : ");

            input = int.Parse(Console.ReadLine());

            for (int i = 1; i <= input; i++)

            {

                for (p = 1; p <= i; p++)

                {

                    if (lastInt == 1)

                    {

                        Console.Write("0");

                        lastInt = 0;

                    }

                    else if (lastInt == 0)

                    {

                        Console.Write("1");

                        lastInt = 1;

                    }

                } Console.Write("\n");

            }

            Console.ReadLine();

        }

    }

}

C# Program to Count the Number of 1's in the Entered Number

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace ConsoleApplication16

{

    class Program

    {

        static void Main(string[] args)

        {

            int m, count = 0;

            Console.WriteLine("Enter the Limit : ");

            m = int.Parse(Console.ReadLine());

            int[] a = new int[m];

            Console.WriteLine("Enter the Numbers :");

            for (int i = 0; i < m; i++)

            {

                a[i] = Convert.ToInt32(Console.ReadLine());

            }

            foreach (int o in a)

            {

                if (o == 1)

                {

                    count++;

                }

            }

            Console.WriteLine("Number of 1's in the Entered Number : ");

            Console.WriteLine(count);

            Console.ReadLine();

        }

    }

}

Wednesday 10 March 2021

Paging & Search Functionality In Asp.Net MVC

 Step1: In SQL server create database ProductsDB. In this database create one table Product  with following columns


Step2: Create Asp.Net MVC Project named as SearchInMVC and select ‘Empty’ ‘MVC’ template as shown in fig below
Step3: Right click on Models folder & add AdoNet Data Model in which select ‘DB first approach from database’ 

Note: Before adding controller build your solution once

Step4 : Add following code in HomeController

 public class HomeController : Controller
    {
        ProductDbEntities db = new ProductDbEntities();
        public ActionResult Index(string searchBy, string search, int? page)
        {

            if (searchBy == "ProductName")
            {
                return View(db.Products.Where(x => x.ProductName.StartsWith(search) || search == null).ToList().ToPagedList(page ?? 1,3));
            }
            else if (searchBy == "Rating")
            {
                return View(db.Products.Where(x => x.Rating.ToString().StartsWith(search) || search == null).ToList().ToPagedList(page ?? 1, 3));
            }
            else
            {
                return View(db.Products.Where(x => x.Price.ToString().StartsWith(search) || search == null).ToList().ToPagedList(page ?? 1, 3));
            }
            
        }

Step6: Add following code in Index.cshtml

@using PagedList;
@using PagedList.Mvc;
@model IPagedList<MVCDemo.Models.Product>
@{
    ViewBag.Title = "Home Page";
}

<div style="padding:5px">
    <p>
        @using (Html.BeginForm("Index", "Home", FormMethod.Get))
        {
            <b>SearchBy:</b> @Html.RadioButton("searchBy", "ProductName") <text> ProductName</text>
            @Html.RadioButton("searchBy", "Rating")<text> Rating </text>
            @Html.RadioButton("searchBy", "Price")<text> Price</text> <br />
            @Html.TextBox("search") <input class="btn btn-success" type="submit" value="Search" />
        }
    </p>

    <div class="jumbotron">
        <h1>Amazon Shopping</h1>


        <div class="container" style="font-family:Arial, Helvetica, sans-serif">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>Product</th>
                        <th>Company</th>
                        <th>Price</th>
                        <th>Ratings</th>
                        <th>Sales(Quantity)</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @if (Model.Count() == 0)
                    {
                        <tr>
                            <td>Records Not found</td>
                        </tr>
                    }
                    else
                    {
                        foreach (var item in Model)
                        {
                            <tr>
                                <td>@item.ProductName</td>
                                <td>@item.CompanyName</td>
                                <td>@item.Price</td>
                                <td>@item.Rating</td>
                                <td>@item.Sales</td>
                                <td>
                                    <a href="#"><i class="glyphicon glyphicon-pencil"></i></a>&nbsp;&nbsp;
                                    <a href="#"><i class="glyphicon glyphicon-remove"></i></a>
                                </td>
                            </tr>
                        }
                    }

                </tbody>

            </table>
            @Html.PagedListPager(Model,Page => Url.Action("Index",new { Page }), new PagedListRenderOptions()
       { Display = PagedListDisplayMode.IfNeeded, DisplayPageCountAndCurrentLocation = true, DisplayItemSliceAndTotal = true})

        </div>
    </div>
</div>

Now Run the project and see the output which looks like below



PostedBy:pankaj_bhakre