Thursday, March 29, 2018

Easy Ploicy

Angular2

1.What is the difference between angulr 1 and 2
2.Why you have used angular 2 .any special reason.
4. Optimization of angular2 application
5. What is cors?
Ans : Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served

6. What are the parameter of cors
Ans: Headers, Methods, Origin.

7. What is angular CLI?
Ans : It is a command line tool for creating angular apps. 

8. What is the difference between null and undefined?
Undefined means a variable has been declared but has yet not been assigned a value. Null is an assignment value. It can be assigned to a variable as a representation of no value.

Web Api
1. What are the http verbs available in web api?
Ans: 

GET
POST
PUT
HEAD
DELETE
PATCH

1a. What to do to support Options in Web API
Ans: https://www.jefclaes.be/2012/09/supporting-options-verb-in-aspnet-web.html

2. Difference between http put and patch?
Ans: The HTTP PATCH type should be used to update any partial resources. 

When you want to update a resource with PUT request, you have to send the full payload as the request whereas with PATCH, you only send the parameters which you want to update.

3. Can we use put for insertion?
Ans : Yes

4. Why we use post..whether for updating or insertion.
Ans : For insertion

5. Attribute routing
6. Can web api return view?
Ans No

6a. By default verb in web api.
Ans : Post

7. What are the return type in web api
Ans 
  1. Void
  2. Any Entity/Datatype
  3. HttpResponseMessage
  4. IHttpActionResult
8. In which format we get the response in web api
Ans http://www.tutorialsteacher.com/webapi/request-response-data-formats-in-web-api

9. How to implement the security in web api

MVC

1. MVC Application life cycle
2. What is routing and rewriting?
Ans :

A redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL.


A rewrite is a server-side rewrite of the URL before it’s fully processed by IIS. This will not change what you see in the browser because the changes are hidden from the user.

Source https://weblogs.asp.net/owscott/rewrite-vs-redirect-what-s-the-difference

2. Custom view engine
4. Can we make our custom view engine
5. What is razor engine
6. How to implement custom validator in MVC?
Ans : using  ValidationAttribute 

7. What type of validation are available in MVC
8. What is CSRF
9. Which interface is used for custom validator


JavaScript
1. What is closure function
2. What is difference between var and let
3. How to implement polymorphism in JavaScript
4. Prototype function
5. Interface in JavaScript
6. IIFY  function IN JavaScript

JQuery
1. Why we use jquery
2. What is $.nocnflict function
3. Can we make our own sign instead of $
4. How many selectors in jquery

C#
1. When to use interface and abstract
2. Which design pattern i have used
3. What is chain of responsibility pattern
4. Generics delegate

5. Tell me the name of few generics delegate
Ans : Func, Action and Predicate are generic inbuilt delegates present in System namespace.

Sql
1. What is view
2. Can we perform insert update delete on view
3. Can we pass the parameter in view
Ans No

You can either create a table valued user defined function that takes the parameter you want and returns a query result.

4. If we can not pass the parameter in view then what will be we use
Ans: 

5. Can we create the non clustered index on primary key.
Ans Yes
5. How to forcefully create the non clustered index on primary key
Ans :

CREATE TABLE TestTable
(ID INT NOT NULL PRIMARY KEY NONCLUSTERED,
Col1 INT NOT NULL)

GO'
6. Why we use indexes
7. Difference between rank and dens rank.

Monday, March 26, 2018

Sopra Steria

1.What is MVC life cycle?
2.What is FormBuilder?
3.What is Form Group?
4.How will unit test in angular2
5.How will you optimize sql squery ?
6.How to implement security in MVC?
7. How will you use Web API?
8. What is the alternate of boxing and unboxing?

Difference between snapshot and subscribe of ActivatedRoute.

snapshot used when there is only one redirection on same component. If there is multiple redirection  than snapshot will not work. In that case subscription will be good.

Suppose you can component which is showing three product

Samsung
Nokia
iPhone

on click of each product use ou have used route.Navigation which redirect to show the detail in below portion of page.
on first click the instance of detail component created so constructor invoked, and in second click insatnce of detail component will not be created since it is already exist, so constructor will not be invoked. In that case snapshot property will be useless.

Source : https://yakovfain.com/2016/11/20/angular-2-implementing-master-detail-using-router/

Saturday, March 24, 2018

Reduce

Reduce takes all of the elements in an array, and reduces them into a single value.

reduce passes your callback four arguments:

The current value
The previous value
The current index
The array you called reduce on

internal of reduce

var numbers = [1, 2, 3, 4, 5],
    total = 0;
   
numbers.forEach(function (number) {
    total += number;
});

While this isn't a bad use case for forEach, reduce still has the advantage of allowing us to avoid mutation. With reduce, we would write:


var total = [1, 2, 3, 4, 5].reduce(function (previous, current) {
    return previous + current;
}, 0);

Thursday, March 22, 2018

Pass By Value and Pass By reference

//Rextester.Program.Main is the entry point for your code. Don't change it.
//Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Rextester
{
     public class NewClass
     {
         public int i=0;
       
     }
    public class Program
    {
        public static void Main(string[] args)
        {
            //Your code goes here
            Console.WriteLine("Hello, world!");
         
            int a=6;
            Add(a);
            Console.WriteLine(a);// Print 6
         
         
         
             a=8;
            AddRef(ref a);
            Console.WriteLine("Ref "+ a);//Print 9
         
         
            int b;
            AddOut(out b);
            Console.WriteLine("Out "+ b);// Print 10
         
         
            NewClass obj = new NewClass();
            obj.i=10;
            AddClassObject(obj);
            Console.WriteLine("New Class Value "+ obj.i);// Print 10
         
        }
     
       private static void AddClassObject(NewClass obj)
       {
           obj.i=19;
           Console.WriteLine("Class Value "+ obj.i);// Print 10
       }
     
        private static void Add(int a)
        {
            a=10;
            Console.WriteLine(a);// Print 10
        }
     
        private static void AddRef(ref int a)
        {
            a=9;
            Console.WriteLine(a);//Print 9
        }
     
        private static int AddOut(out int b)
        {         
            string s="10s";
         
            int i;
            if(int.TryParse(s,out i))
                Console.WriteLine("Int i value " + i);
                     
            b=10;
            Console.WriteLine(b);
            return 80;
        }
    }
}

Monday, March 19, 2018

const in Angular 2

If the variable foo is a const that points to an object — we can’t make foo point to another object later on:

const foo = {};
foo = {}; // TypeError: Assignment to constant variable.
But we can however mutate, make changes to, the object foo points to, like so:

const foo = {};
foo['prop'] = "Moo"; // This works!
console.log(foo);
If we want the value of foo to be immutable we have to freeze it using Object.freeze(…​).

When we freeze an object we can’t change it, we can’t add properties or change the values of properties, like so:

const foo = Object.freeze({});
foo.prop = 123;
console.log(foo.prop) // undefined

Friday, March 16, 2018

Promise in Angular

For asynchronus function call we use call back in Java script. 

Promise API

For asynchronus function call we use Promise. 

The promise constructor takes one function argument. That function, in turn, has two arguments – resolve (we call this if the async operation is successful) and reject (if the async operation fails).

States of a promise

1. Pending
A promise is pending when you start it. It hasn’t been resolved or rejected. It is in a neutral state.

2. Fulfilled
When the operation is successful, a promise is considered fulfilled or resolved.

3. Rejected
If an operation fails, the promise is rejected.

When the promise is no longer in a pending state then…

Exactly… then is the keyword we will use to tell the promise what to do when it succeeds / fails.

The then method has two arguments (functions) which get called based on whether the promise is resolved or rejected. We can pass arguments to these methods through the resolve and reject methods in the Promise constructor.


// To reject promise change value of CONDITION to false
const CONDITION = true;

// Data passed when the promise is resolved
const DATA = 'hello world';

// Error passed when the promise is rejected
const ERROR = new Error('Ooops!');

const promise =
  new Promise((resolve, reject) => {
  // do some async stuff

  if (CONDITION) resolve(DATA);
  else reject(ERROR);
  })
  .then(
  (data) => { console.log(data); },
  (err) => { console.log(err); }
  );

ES6 adds some more syntactic sugar by allowing you to write the same code like this.

.then((data) => { console.log(data); })
.catch((error) => { console.log(error); });

But All Browsers Don’t Support ES6
You don’t need to worry about that. If you’re working with Angular 2, React, or any other modern framework or library, you’ll be using a transpiler (such as babel with ES6 and tsc with Typescript).

That means that the code will be converted to a readable and usable version for older browsers that don’t support ES6.

Observable in Angular

Observables are a lazy collection of values. Observables open the continuos channel of communication where multiple
values are emitted over time.

Example : Internet service on mobile is an example of observable it is available for those who have subscribed it.

Observable.Component.ts

import { Component, OnInit } from '@angular/core';  
import {Observable} from 'rxjs/Observable'  
@Component({  
  selector: 'app-observable-demo',  
  templateUrl: './observable-demo.component.html',  
  styleUrls: ['./observable-demo.component.css']  
})  
export class ObservableDemoComponent implements OnInit  
 {  
  private data: Observable<string>;  
  private fruits: Array<string> = [];  
  private anyErrors: boolean;  
  private finished: boolean;  
  
  processed=false;  
  
  constructor() { }  
ngOnInit(){  
}  
  
start(){  
  this.data = new Observable  
  (  
    observer =>   
    {  
            setTimeout(() =>   
            {  
                observer.next('Apple');  
            }, 1000);  
              
            setTimeout(() =>   
            {  
                observer.next('mango');  
            }, 2000);  
            setTimeout(() =>   
            {  
                observer.next('Orannge');  
            }, 3000);  
            setTimeout(() =>   
            {  
                observer.complete();  
            }, 4000);  
              
   }  
);  
let subscription = this.data. subscribe(  
fruit => this.fruits.push(fruit),  
    error => this.anyErrors = false,  
    () => this.finished = true  
);  
this.processed=true; }} 

Observable.Component.html

<p style="padding-left:300px;font-weight:bold;font-size: 50px">Observable Basics</p>  
<hr/>  
<b>Observable Data </b>  
 <div style="border: 3px;padding-left:150px;text-align: " *ngFor="let f of fruits"> {{ f | uppercase }}</div>  
 <hr>  
<div *ngIf='anyErrors' style="border: 3px;padding-left:0px" >  
  <b>Error Status :</b>   
 {{anyErrors==true? 'error occured ' : 'It All Good'}}   
  <hr>  
</div>  
<div style="border: 3px;padding-left:0px"> <b> completion status : </b> {{ finished==true ? 'Observer completed ': '' }}</div>  
<hr>  
<button style="margin-top: 2rem;" (click)="start()">Start Emitting</button>  

Source : https://www.c-sharpcorner.com/article/observables-with-the-angular-5/

Wednesday, March 14, 2018

Filter in Javascript

It does exactly what it sounds like: It takes an array, and filters out unwanted elements.

Like map, filter is defined on Array.prototype. It's available on any array, and you pass it a callback as its first argument. filter executes that callback on each element of the array, and spits out a new array containing only the elements for which the callback returned true.

var difficult_tasks = tasks.filter(function (task) {
    return task.duration >= 120;
});

What is the use of map function in Javascript?

The map() method is used to apply a function on every element in an array. A new array is then returned.

Here’s what the syntax looks like:


let newArr = oldArr.map((val, index, arr) => {
  // return element to new Array
});


newArr — the new array that is returned
oldArr — the array to run the map function on
val — the current value being processed
index — the current index of the value being processed
arr — the original array

You do have to remember to include a return statement in your callback. If you don't, you'll get a new array filled with undefined. 

Let see what is internal coding of map

var map = function (array, callback) {

    var new_array = [];

    array.forEach(function (element, index, array) {
//You can modify element here
       new_array.push(callback(element)); 
    });

    return new_array;

};

var task_names = map(tasks, function (task) {

    return task.name;


});

Source : https://code.tutsplus.com/tutorials/how-to-use-map-filter-reduce-in-javascript--cms-26209

Tuesday, March 13, 2018

Rategain

1. How can you prevent a cleint by using Action method in MVC?
Ans using ChildActionOnly attribute

2. How can you add extra paramtere in a function wihtout updating method in Web API?
Ans: Send non primtive Data in the form of class object , then you can add properties in class.

3. What are child Action method?
Ans:

A ChildAction method is an action method thought its accessible from the View only, if you invoked this action via an URL then it prompts you an error that we will look down the level in this article.

How to use in View

@Html.Action("SomeActionName", "SomeController")
But can not call it from url.

4. What are Mutex and Monitor?
5. Can we use commit with datareader?
6. class abc{
int i=0;
abc(){
i=i+1;
}
}

abc obj = new abc();

If two client access at same time how will you ensure both would get updated value of i.

7. class test
{
int i;
string str;

}
static void main(args[] arg){
int j;
test a = new test();
}
8. Table A contains following data

Id Name
1 A
2 B
3 C

Table B contains following data

Id Name
1
1
2
2
3
3

Update table B with the help of Table A.

Tuesday, March 6, 2018

Drawback of Property Injection

1.One of the drawback of  property injection is that it does not ensures dependency Injection. You can not guarantee that certain dependency is injected or not, which means you may have an object with incomplete dependency. On other hand constructor Injection does not allow you to construct object, until your dependencies are ready.

2. Constructor injection enforces the order of initialization and prevent circular dependencies while in case of property injection it is not clear in which order things need to be instantiated.

3. By using setter injection, you can override certain dependency which is not possible with constructor injection because every time you call the constructor, a new object is gets created.

4. If Object A and B are dependent each other i.e A is depends ob B and vice-versa. You can  not create both object bcz A object cannot be created until B is created and vice-versa. This (circular dependencies ) can be resolve through property-injection. Objects constructed before property invoked.



Monday, March 5, 2018

Difference Between Correlated Subquery and Nested Subquery

1. Correlated subquery  runs once for each row selected by the outer query. It contains a reference to a value from the row selected by the outer query,

Nested subquery runs only once for the entire nesting (outer) query. It doe not contain any reference to the outer query row.

2. Correlated subquery follows down to top approach i.e main query executed first (event though parenthesis are present) and then child query.

We can save, inner query condition is used in the outer query.

Nested subquery follows top-down approach i.e child query executed first and then parent query.

We can say Outer query condition is used in the inner query.

3. Example of Co-related Query:

select e1.emplname,e1.salary, e1.deptno from emp e1

where  e1.salary =(select max(salary) from emp e2 where e2.deptno= e2.deptno)

Example of Subquery:
select empname,salary,deptno from emp where (deptno,salary) in (select deptno,max(salary) from emp group by deptno)



Followers

Link