Hello Everyone…..

Myself Ramesh Sai working as a Software Developer in a company located in Hyderabad.I like coding and learning new techniques.I am having good command on C#,ASP.NET,SQL server,MVC,LINQ,Entity Framework,JSON

Advertisements

What’s new in Angular compared to AngularJS

Let’s go through the main differences between AngularJS and Angular:

1)Angular is a complete rewrite of AngularJS
2) An Angular application and its architecture are different from AngularJS. The main building elements for Angular are modules, components, templates, metadata, data binding, directives, services and dependency injection
3) Angular does not have a “scope” concept or controllers, instead, it uses a component hierarchy as its main architecture
4) Angular follows a modularity concept. Similar functionalities are kept together inside modules. This gives Angular an optimized lighter core
5) The controller concept, which was present in AngularJS, was removed from Angular 2 and above which are component based UI. This help developers divide applications in components with desired features. These helped improve the flexibility and reusability compared to AngularJS
6) Angular expression syntax is focused on “[ ]” for property binding, and “( )” for event binding
7) With AngularJS, building a search engine (SEO) friendly Single Page Application was a major difficulty. But this bottleneck was eliminated with Angular 2 by enabling application rendering in the server. These tasks are possible thanks to the Angular Universal module.
Angular 2 also recommends using the TypeScript language, which introduces these features:

1)Static Typing
2) Object Oriented Programming based on classes
3) Support reactive programming using RxJS
On top of TypeScript features, Angular also includes the benefits taken from ES6:

1)For/Of loops
2) Improved dependency injection
3) Iterators
4) Reflection
5) Dynamic loading
6) Asynchronous template compilation
7) Simpler Routing
From Angular 2 to Angular 4:
There were some major changes, but mostly on the project structure with lots of refactors that made the framework more stable.

1)Smaller and faster. The upgrade from 2.0 to 4.0 has reduced the bundled file size by 60% while also improving the applications speed.
2) Angular 4 is compatible with newer versions of TypeScript 2.1 and TypeScript 2.2.
3) Angular Universal: The vast majority of the Angular Universal code has been merged into Angular core.
4) Animation Package: Animations taken from the Angular core and set within their own package. Meaning that if you don’t use animations, the excess code won’t end up in your app.
From Angular 4 to Angular 5:
Angular 5 is full of new features, bug fixes, performance improvements, and some code deprecation as a clean up of the refactors from version 4.

1)Optimizations to the build process that reduces the application size by removing unnecessary code.
2) Material Design components with server-side rendering.
3) Angular Universal improvements for code allocation between the server and client-side versions of the application.
4) Improved compiler that supports incremental compilation meaning faster rebuilds.
5) RxJS (reactive programming library) has been updated to version 5.5.2 or later.
6) BREAKING CHANGES: Angular now requires TypeScript 2.4.x.

Share Post To Facebook TimeLine

Requirements:
Basic knowledge of JavaScript and familiarity with Facebook open graph (og ) meta data is required. It is assumed that you have, or know how to obtain Facebook application id (if not, please checkout: developers.facebook.com/docs/apps/register ).

Introduction:
In most situation Facebook open graph (og) meta tags will be filled while a page is being generated – before it is served to the browser. But there are situation where you want to change data to be shared dynamically with JavaScript, after the page has been served to the browser.

For example, you are creating a quiz and you want to enable the players to share their result on the Facebook, while at the same time linking the shared content to the beginning of the quiz – so that player’s friends could start playing the quiz right away.

One way to accomplish this is to use JavaScript to change data to be shared (title, description and image) while leaving the original quiz url unchanged. Actually, you want or need possibility to share different text and images for the same url.

Implementation:
The quiz might have this og meta data tags:

<meta property=”fb:app_id” content=”124285848214697″ />
<meta property=”og:url” content=”Mention url here” >
<meta property=”og:type” content=”article” >
<meta property=”og:title” content=”Are you the real Star Trek geek?” >
<meta property=”og:description” content=”Sample Description” >
<meta property=”og:image” content=”home.jpg” >
<meta property=”og:image:width” content=”1200″ >
<meta property=”og:image:height” content=”630″ >

But after the quiz has finished you want the player (lets call him George L.) to share something like this:

title: “George L. is the Yoda of the Star Trek!”
description: “George L. is the champion of the Star Trek geekhood – and nobody can beat him. Or … ? Click to play and prove to the George L. that you are as good as him!”
image: Some custom image to celebrate the player success.

Add this JavaScript somewhere between <head></head> to include Facebook JavaScript SDK

Note: Enter your appId instead of 124285848214697 .

To display share dialogue with dynamically overridden title, description and image use this js code:

that’s it

ASP.NET MVC Application_Error handler in Global.asax

Global.asax:
protected void Application_Error(object sender, EventArgs e)
{
Exception exception = Server.GetLastError();
Response.Clear();

if (exception != null)
{
Common.WriteErrorLog(exception);
}

HttpException httpException = exception as HttpException;
if (httpException != null)
{
RouteData routeData = new RouteData();
routeData.Values.Add(“controller”, “Error”);
switch (httpException.GetHttpCode())
{
case 404:
// page not found
routeData.Values.Add(“action”, “HttpError404”);
break;
case 500:
// server error
routeData.Values.Add(“action”, “HttpError500”);
break;
default:
routeData.Values.Add(“action”, “Index”);
break;
}
routeData.Values.Add(“error”, exception.Message);
// clear error on server
Server.ClearError();

Response.RedirectToRoute(routeData.Values);
// at this point how to properly pass route data to error controller?
//Response.Redirect(String.Format(“~/Error/{0}/?message={1}”, “Index”, exception.Message));
}
}
Controller :
public class ErrorController : Controller
{
// GET: Error
public ActionResult Index(string error=””)
{
ViewBag.Message = error;
return View();
}

public ActionResult HttpError404(string error = “”)
{
ViewBag.Message = error;
return View();
}

public ActionResult HttpError500(string error = “”)
{
ViewBag.Message = error;
return View();
}
}
to get emails when error occured
protected void Application_Error(object sender, EventArgs e) {

Exception exception = Server.GetLastError();

Response.Clear();

HttpException httpException = exception as HttpException;

string txt = Convert.ToString(httpException);

if (httpException != null) {

string action;

string email = “xxxx@xxxxx.com”;

switch (httpException.GetHttpCode()) {

case 404: // page not found action = ” Error occured in application HttpError404″; break; case 500: // server error action = “Error occured in application HttpError500”; break; default: action = “Error occured in application General”; break;

}

Write Email Sending Code here

Server.ClearError();  //clear Exception in Server

Response.Write(“window.alert(‘Some thing went wrong please try again after some time click OK to continue!!!’);

window.location=’/Home’;”);

}

}

Add Multiple Fields items to List C#

To Add Single Item to List

List<string> list1 = new List<string>();

list1.Add(“1”);

list1.Add(“2”);

list1.Add(“3”);

..

..

To Add Multiple items to List

List<string[]> list2 = new List<string[]>();

var firstitem = “1,2,3,4,…”;

var seconditem = “one,two,three,four,………”;

for(int i=0; i < firstitem.split(‘,’).Count();i++)

{

list2.Add(new string[]{firstitem.split(‘,’)[i],seconditem.split(‘,’)[i]});

}

output:

By Expanding List at debugging it would look like

>list2 | Count = 4 (depends on items count) > [0] >

[0] : “1”

[1] : “one”

Convert Server Time to System Time

Declare

private static TimeZoneInfo INDIAN_ZONE = TimeZoneInfo.FindSystemTimeZoneById(“India Standard Time”);

and use

DateTime indianTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, INDIAN_ZONE);

Previously i used to have 11 hours 30 minutes time gap between server & system time.

Now, after using above method both system and server time synched…

That’s All Folks !!!

Handling cookies using JQuery

Step 1) Creating Cookie

Add below .js file to your application

http://cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js

$.cookie(“first”, “Ramesh”);

Here,first represents cookie name and “Ramesh” represents cookie value

Step 2) Assign Cookie value to a textbox

Let’s create a textbox

<input type=”text” id=”name” placeholder=”Enter Name”/>

$(‘#name’).val($.cookie(“first”));

 

That’s it cookie value will be assigned to textbox.

That’s all Folks!!!!