program to check number is prime or not

By // 1 comment:
Program to check prime in C#
In Interview its a common question for fresher as well as experience to do code to check given number is prime or not. No matter in which language you written the code but matter is what logic you follow to do this. I hope you all aware about what is prime number if no then let me explain what is prime number
Prime number is a number which is divisible by same number and only by 1. Lets take an example
Suppose we take a number 6. Is it prime number ?
No due to its divisible by 2 & 3 also.
Lets take an another example is 23 is prime number
Yes because its divisible by 1 & 23 only.
Lets Implement these in programming language

Program to check number is prime or not in C#

using System;
namespace example
{
  public class CheckPrime
    {
        public static void Main()
        {
            Console.Write("Please enter a number: ");
            int num;
            num = Convert.ToInt32(Console.ReadLine());
            int j;
            j = 0;
            for (int i = 1; i <= num; i++)
            {
                if (num % i == 0)
                {
                    j++;
        }
            }
            if (j == 2)
            {
                Console.WriteLine("Wow! Entered Number is a Prime Number");
            }
            else
            {
                Console.WriteLine("Oops! Entered Number is Not a Prime Number");
            }
            Console.ReadLine();
        }
    }
}

Output of prime number check in C#

Please enter a number 23
Wow! Entered Number is a Prime Number

Rootscope in angular JS

By // No comments:
$rootscope in angualr
In this article i explain what is rootscope in angular js & how its different from normal scope. First thing we have notice is every application has a single rootscope and we can use this entirely in application. Simple means is $rootScope is available for all controller but the $scope only within the controller. In another way we can say that $scope is an object that is accessible to current controller & $rootScope is also an object which is accessible from anywhere in the application .
For example if you make any variable global then it will accessible from everywhere & in case of local variable only local accessible are present same like $scope & $rootScope. $scope is created with ng-controller while $rootscope is created with ng-app. Here we give an example of the $rootScope. you have to also notice that controller's color variable does not overwrite the rootScope's color value in below example.

rootScope in Angualr JS

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
  <div>I am not in any controller </div>
  <p>rootScope Properties Call :- {{color}}</p>
  <div ng-controller="myCtrl">
    <fieldset>
      <legend>
        I am in Controller
      </legend>
      <p>Controller Properties Call :- {{color}}</p>
      <p>rootScope Properties Call :-  {{$parent.color}}</p>
   </fieldset>
  </div>
  <div>Again i am not in any Controller </div>
  <p>rootController property color is called :- {{color}}</p>
 <script>
   var app = angular.module('myApp', []);
   app.run(function($rootScope) {
     $rootScope.color = 'blue';
   });
   app.controller('myCtrl', function($scope) {
     $scope.color = "red";
   });
 </script>
</body>
</html>

output of rootScope in Angualr JS

I am not in any controller
rootScope Properties Call :- blue
I am in Controller
Controller Properties Call :- red
rootScope Properties Call :- blue
Again i am not in any Controller
rootController property color is called :- blue

Nested Controller In Angular JS

By // No comments:
Nested Controller in Angular Js In this article we discuss about how to get main controller object or value in child controller. I am not going to discuss here what is angular js controller. Some time in interview such type of question asked by interviewer. Here we make a two controller one is main controller and second is subcontroller which is inside of main controller. Now suppose in code we set title variable in both controller & want to access main controller title variable to subcontroller. I Here is complete code about above scenario you have to just copy paste & execute it.

Nested Controller in Angualr JS

<!DOCTYPE html>
<html>
<head lang="en">
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
 <script>
   angular.module('app', []);
   angular.module('app').controller("MainController", function($scope){
   $scope.title = 'I am Parent Controller Title';
   });
   angular.module('app').controller("SubController", function($scope){
    $scope.title = 'I am Sub-Controller Title';
    });
</script>
</head>
<body ng-app='app' ng-controller='MainController'>
<div class='container'>
  <p style="color:Red">Angular JS Main Controller - {{title}}</p>
  <div ng-controller='SubController'>
    <p style="color:green">
      Angular JS SUB Controller - {{title}}</p>
    <p style="color:blue">Angular JS Call Main Controller object inside child controller - {{$parent.title}}</p>
   </div>
</div>
</body>
</html>

Output of nested controller example in Angualr JS

Angular JS Main Controller - I am Parent Controller Title
Angular JS SUB Controller - I am Sub-Controller Title
Angular JS Call Main Controller object inside child controller - I am Parent Controller Title

Angular js Custom Directive

By // No comments:
Angular Js Directive
Here we discuss angular js custom directive.In angular js directive is one of the main feature. There are lots of angular js inbuild directive like ng-model,ng-hide,ng-show etc and we use it on our project everyday. But question is how to make my own directive in angular js. Good thing is angular js allow you to extend this.If you learning angualr js then you have to good knowledge of angular directive. Angualr js support to create custom directive for following type of elements as well as tags.I called these shortly EACM where E stand for element A stand for Attribute C stand for class and last M stand for comment. Here we discuss all this one by one
1. Element (E) : If we restrict custom directive with Element then directive execute only when a matching element is encountered.
2. Attribute (A): Only execute when a matching attribute is encountered.
3. Class (C): Directive execute only when a matching class is encoutered.
4. Comment (M): Directive execute only when a matching comment is encoutered.

Angular js Directive

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body ng-app="myApp">
<custom-directive></custom-directive>
<div custom-directive></div>
<script>
    var app = angular.module("myApp", []);
    app.directive("customDirective", function () {
        return {
            restrict: "A",
            template: "<h4>Restict the directive with attribute restiction!</h4>If you execute this programm then custom-directive which is element is not execute because we restrict with attribute "
        };
    });
</script>
</body>
</html>

Explanation & Enhancement

Suppose if you put two are more than two restrict like restrict:"AC" then its restrict for attribute as well as class also. In this article i will  soon update how to call function inside custom directive.
link: function (scope, element, attrs) { element.on("click", ".member-link", function () { }); }

MVC Architecture

By // 1 comment:
Mvc Architecture
In this topic , you will get an basic concept  of MVC architecture or MVC design pattern. Here we discuss ASP . net MVC pattern.  MVC architecture has existed in technology very  long time approx more than 10 year. MVC is not related with only ASP.NET it's also vastly used in other programming language like MVC in java , PHP MVC , angular JS etc . Angualr Js is scripting language and its also follow the MVC design pattern. Technically implementation of MVC in all languages is slightly different , but conceptually it remains the same.
Let's understand the MVC architecture in ASP.NET.
MVC stands for Model, View and Controller and it basically used for developed the web based application.I am talking here web based application then the question arises is MVC architecture is not good for Windows form ? Answer is no if you are working with window programming then MVP pattern is good and if you are working with WPF then MVVM pattern is good. MVC is one of the main framework to create a extensible web based project.

Mvc Architecture in ASP .Net [MVC Components]

MVC Architecture  Design pattern

Model : Model is used for managing the data.Model is used for set the property & also business logic As from the above picture we can see that it also interact with database . MVC not given any  data access layer but in this design pattern we are able to implement these access layer and implement the business login in Model class. For example Student is Model class & this object will fetch the student information from the database (any database like oracle,sql server, mysql) and manipulate it here .It also get back data to database.

View  : View component is a presentation of data in particular format. It also known as presentation layer. View is used for all the UI (user interface) logic. For example in VIEW include all the html like form input type etc & also used for display the data from database which is manipulated from model.

Controller : Controller is very important component in MVC arcticture. MVC Controller act as interface between model & view. Its handle the user request & send it back to user. For example, the Student controller would handle all the interactions and inputs from the Student View and manipulate the database using the Student Model.