Saturday, June 8, 2019

Likes/DisLikes Example with Angular

Step 1:

Download and Install Latest Node.js


URL https://nodejs.org/en/download/


Step 2:


Install Visual Studio Code  (URL:  https://code.visualstudio.com/download)


Step 3:


Install Angular CLI Using the command 


npm install -g @angular/cli




Create a new Angular Application


Create a New Folder in your System (D:\\AngularApp)


Open folder using Visual Studio Code


Open Terminal Using the Ctrl + ` Type the below Command


ng new cars-demo




Below is the folder Structure you will be seeing.


ng g c carsdemo --spec=false


Now you can see the below files gets created in the folder  src\app as shown below


cars-demo.component.ts


import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-cars-demo',
  templateUrl: './cars-demo.component.html',
  styleUrls: ['./cars-demo.component.css']
})
export class CarsDemoComponent implements OnInit {

  constructor() { }
  public cars = [
    {carName: 'Audit', Photo: 'assets/Audit.Jpg', Likes: 0, DisLike: 0},
    {carName: 'Benz', Photo: 'assets/Benz.Jpg', Likes: 0, DisLike: 0}
    ];

  ngOnInit() {
  }
  public LikesCounter(car)
  {
    car.Likes++;
  }

  public DisLikesCounter(car)
  {
    car.DisLike++;
  }
}


cars-demo.component.html

<div align="center" *ngFor="let carobj of cars">
  <h3> {{ carobj.carName }} </h3>

  <img [src]="carobj.Photo" border="1" width="200" height="200" >
  <br/>
  {{carobj.Likes}} |  {{ carobj.DisLike}}
  <br/>
<a href="#" >
  <img src="assets/Like.Jpg" width="30" height="30" (click)="LikesCounter(carobj)" >
</a>
<span>  | </span>

<a href="#" >
  <img src="assets/DisLike.Jpg" width="30" height="30" (click)="DisLikesCounter(carobj)" >
</a>
</div>


Note: Add Images in the Asset Folder for displaying of Image as shown below



Now Go to app.module.ts(To make cars binding Component Run we need to make the following Changes)



Now Go to Index Page in the folder and make the below changes.


Output:

Go to Terminal And Type the Command 


ng s





Wednesday, June 5, 2019

Data Binding Technique using Interpolation in Angular

Interpolation: It is a data binding technique used by angular to bind the model data into any View. It uses angular Data Binding Expression  " { }"

Step 1:

Download and Install Latest Node.js

URL https://nodejs.org/en/download/

Step 2:

Install Visual Studio Code  (URL:  https://code.visualstudio.com/download)

Step 3:

Install Angular CLI Using the command 

npm install -g @angular/cli



Create a new Angular Application

Create a New Folder in your System (D:\\AngularApp)

Open folder using Visual Studio Code

Open Terminal Using the Ctrl + ` Type the below Command

ng new databinding



Below is the folder Structure you will be seeing.



Go to that Path and run the below command to create a component using Visual Studio Code

Now you can see the below files gets created in the folder  src\app as shown below

data-binding.component.ts

import { Component, OnInit } from '@angular/core';

@Component({

  selector: 'app-data-binding',
  templateUrl: './data-binding.component.html',
  styleUrls: ['./data-binding.component.css']
})

export class DataBindingComponent  {

  
  public title = 'Product Details';
  public product =
  {
    Name: 'Samsung TV',
    Price: 4500.64,
    Qty: 2,
    Mfd: new Date('2019/02/20'),
    Preview: 'assets/Samsung.JPG'
  };
  public GetTotal() {
    return this.product.Qty * this.product.Price;
}

}


data-binding.component.html 

<H1> Data Binding </H1>
 <h3> {{ title }} </h3>
<dl>
  <dt> Name </dt>
  <dd> {{ product.Name }} </dd>
  <dt> Price </dt>
  <dd> {{ product.Price}}</dd>
  <dt>  Quantity </dt>
  <dd> {{ product.Qty}}</dd>
  <dt> Manufactured Date </dt>
  <dd> {{ product.Mfd.toLocaleDateString() }} </dd>
  <dt> Preview</dt>
  <dd>
    <img src="{{product.Preview}}" width="100" height="100">
  </dd>
  <dt> Total Amount</dt>
  <dd> {{GetTotal() }}</dd>

  </dl>

Note: Add any Image in the Asset Folder for displaying of Image.




Now Go to app.module.ts(To make Data binding Component Run we need to make the following Changes)



Now Go to Index Page in the folder




Output:

Go to Terminal And Type the Command 
ng s




Output:



Sunday, February 10, 2019

Expression bodied members in C Sharp 7.0

C# 6.0
 
Expression bodied Methods
Expression bodied Properties
 
C# 7.0
 
Expression bodied constructor
 
Expression bodied destructor
 
Expression bodied getters
Expression bodied setters
Expression bodied Events.
 
Expression bodied Methods:

Let us learn the Previous Release of Expression bodied Method in C sharp 6.0.

Sample Syntax :

public string GetUserDetails

() => $ "{UserId} + {UserName} + {EmailId} + {ContactNumber}"; 

 Example:

class User

    {    
        public int UserId { get; set; }  
        public string UserName { get; set; }  
        public string EmailId { get; set; }  
        public string ContactNumber { get; set; }  
        public string GetUserDetails() => $"{UserId} + {UserName} + {EmailId} + {ContactNumber}"; 

    }


    class Program
    {       

static void Main(string[] args)        {
            User obj = new User();
            obj.UserId = 001;
            obj.UserName = "Rajakonda Uday Kumar";
            obj.EmailId = "rajakondauday@gmail.com";
            obj.ContactNumber = "123456";
            Console.WriteLine(obj.GetUserDetails());
            Console.ReadLine();
        }
    }

Output:


 
There might be the situation where we want to override the ToString method in that case
class User
    {   
        public int UserId { get; set; } 
        public string UserName { get; set; } 
        public string EmailId { get; set; } 
        public string ContactNumber { get; set; } 
        public string GetUserDetails() => $"{UserId} + {UserName} + {EmailId} + {ContactNumber}";
        public override string ToString() => $"{UserId} + {UserName} + {EmailId} + {ContactNumber}";
    }

    class Program
    {
        static void Main(string[] args)
        {
            User obj = new User();
            obj.UserId = 001;
            obj.UserName = "Rajakonda Uday Kumar";
            obj.EmailId = "
rajakondauday@gmail.com";
            obj.ContactNumber = "123456";
            Console.WriteLine(obj.ToString());
            Console.ReadLine();
        }
    }



 
Expression Bodied Properties:

class User
    {   
        public int UserId { get; } = 0001;
        public string UserName { get; } = "Rajakonda Uday Kumar";
        public string EmailId { get;} = "
rajakondauday@gmail.com";
        public string ContactNumber { get; } = "123456";
        public string GetUserDetails() => $"{UserId} + {UserName} + {EmailId} + {ContactNumber}";
        public override string ToString() => $"{UserId} + {UserName} + {EmailId} + {ContactNumber}";
    }

    class Program
    {
        static void Main(string[] args)
        {
            User obj = new User();
            Console.WriteLine(obj.ToString());
            Console.ReadLine();
        }
    }





In C Sharp 7.0
 
Expression bodied constructor
 class User
    {
        public int UserId { get; } = 0001;
        public string UserName { get; } = "Rajakonda Uday Kumar";
        public string EmailId { get;} = "
rajakondauday@gmail.com";
        public string ContactNumber { get; }
        public User()=> ContactNumber= "99898955555";
    }
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(new User().ContactNumber);
            Console.ReadLine();
        }
    }

Output:


 
Expression bodied destructor
class User
    {
        public int UserId { get; } = 0001;
        public string UserName { get; } = "Rajakonda Uday Kumar";
        public string EmailId { get;} = "
rajakondauday@gmail.com";
        public string ContactNumber { get; }
        public User()=> ContactNumber= "99898955555";
        ~User() => Console.WriteLine("Destructor Method");
    }

    class Program
    {
        static void Main(string[] args)
        {
            Details();
            GC.Collect();
            Console.ReadLine();
        }

        public static void Details()
        {
            Console.WriteLine(new User().ContactNumber);
            User user = new User();
        }

    }

Expression bodied getters & setters
class User
    {
        public Dictionary<int, string> UserList = new Dictionary<int, string>();
        public int UserId { get; } = 101;
        public string UserName { get; } = "Rajakonda Uday Kumar";
        public string EmailId { get;} = "
rajakondauday@gmail.com";
        public string ContactNumber { get; }
        public string UserDetails
        {   get => UserList[UserId]; 
            set => UserList[UserId] = value; 
         }
    }

    class Program
    {
        static void Main(string[] args)
        {
            User obj = new User();
            obj.UserList.Add(101, "A");
            obj.UserList.Add(102, "B");
            Console.WriteLine(obj.UserDetails);
            Console.ReadLine();
        }
    }

Examples:

class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($" {new Employee().EmployeeDetail()}");
            Console.ReadLine();
        }
    }

    class Employee
    {
        int empId { get; } = 101;
        string Name { get; } = "ABC";
        string Address { get; } = "Hyderabad";
        double Salary { get; } = 1000;

        public double HRA() => (Salary * 40) / 100;
        public string EmployeeDetail() => $"EmployeeId: {empId}\n EmployeeName: {Name}\nEmployeeAddress: {Address}\nEmployeeHRA: {HRA()}";
    }

 
Output:
 

2) Example:
class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($" {new Employee().EmployeeDetail()}");
            Console.ReadLine();
        }
    }
    class Employee
    {
        int empId { get; } = 101;
        string Name { get; } = "ABC";
        string Address { get; } = "Hyderabad";
        double Salary { get; } = 1000;
        public Employee() => Salary = 1000;
        public double HRA() => (Salary * 40) / 100;
        public string EmployeeDetail() => $"EmployeeId: {empId}\n EmployeeName: {Name}\nEmployeeAddress: {Address}\nEmployeeHRA: {HRA()}";
        ~Employee() => Console.WriteLine("\n Destructor");
    }
 

C Sharp Throw Exception Directly


From C sharp 7.0 we can throw an exception directly through expression.

New Access Specifier in C sharp 7.2

In C# 7.2 a private protected has been added. So they are total 6 access specifier
 
From C Sharp 7.2.
  •         public
  •         protected
  •         internal
  •         private
  •         protected internal
  •         private protected
  To know about previous access specifier please go through this.


Private Protected: It really means protected AND internal.

 
From the above Example you can see that it gives Me Error. Reason is
 
 

To Fix this,
In Visual Studio 2017 first, we need to change the Language Type to C Sharp 7.2 as shown below

Goto Project File-> Right Click and Select Properties.

That is - member is accessible only to child classes which are in the same assembly, but not to child classes which are outside assembly.

 
Now let me try to access this From the Outside Assembly.
1) private protected member is inaccessible outside the assembly for the child class.


 
2) private protected member is inaccessible inside the assembly for non-inherited class.
 

Error:


Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...