Tuesday, November 10, 2015

ASP.Net MVC draw chart.js with jQuery Ajax call

Following is a Ajax call example:
//Read
var GetDataList = function (date, callback) {
    $.ajax({
        type: 'GET',
        url: '/Test/GetMyDataList',
        dataType: 'html',
        data: {
            date: date
        },
        success: function (data) {
            if (callback) callback(data);
        }
     });
 };
The above example passed data as parameter which contains date, and once the call is success, another callback function will be used to process the returned data.
//Save
var UpdateDatalist = function (model, callback, callback2) {
    $.ajax({
        type: 'POST',
        url: '/Test/UpdateDatalist',
        dataType: 'json',
        processData : false,
        data: JSON.stringify(model),
        cache: false,
        success: function (data) {
            if (data.ReturnedModel) callback2(data);
            if (isError(data)) return;
            if (callback) callback(data);
        }
    });
};
The above example send a JavaScript object as a JSON string to the server with an AJAX request, you need to convert the JavaScript object to a JSON string and send the string as raw data.

HTTP requests can be send as either, GET, POST, PUT, DELETE or HEAD requests.

Note here it's better to use List<Class> over Dictionary<Key, String> because List can be converted directly into JSON while you need to write customized code to convert Dictionary to JSON data.

Source:
http://forums.asp.net/t/2000850.aspx?json+data+to+a+chart+via+a+JsonResult+Action+in+MVC
https://gist.github.com/dancameron/18ad7e46399406259323
http://stackoverflow.com/questions/19894952/draw-a-chart-js-with-ajax-data-and-responsive-a-few-problems-and-questions
http://tutorials.jenkov.com/jquery/ajax.html#receiving-json

Applying Generic Repository and Unit of Work Pattern with ASP.NET MVC and Entity Framework


Source:
http://www.thereformedprogrammer.net/is-the-repository-pattern-useful-with-entity-framework/
http://www.thereformedprogrammer.net/is-the-repository-pattern-useful-with-entity-framework-part-2/
http://stackoverflow.com/questions/25953881/unit-of-work-repository-service-layer-with-dependency-injection
http://blog.longle.net/2013/05/11/genericizing-the-unit-of-work-pattern-repository-pattern-with-entity-framework-in-mvc/
http://techbrij.com/generic-repository-unit-of-work-entity-framework-unit-testing-asp-net-mvc
http://stackoverflow.com/questions/16572743/generic-repository-with-data-access-layer
http://www.codeguru.com/csharp/.net/net_asp/mvc/using-the-repository-pattern-with-asp.net-mvc-and-entity-framework.htm
http://ctrlcvprogrammer.blogspot.ca/2015/05/wanted-to-execute-stored-procedure-in.html

Wednesday, November 4, 2015

How to applying Store Procedures to build Entity Framework in ASP.Net MVC project


After you have successfully build your Entity Framework, you can update it if your tables or store procedures have been changed. Right click on the Entity Framework model in your solution explorer, choose Open, and click on Model Browser. Then right click on the root node of the model, and choose Update Model from Database, the data model will be updated. If you changed the database connection string in web.config, and create a new database connection using different connection name, the Model Browser will start a new wizard to connect to the new database. In this way you can switch different database for the predefined Entity Framework.

Source:
http://weblogs.asp.net/dotnetstories/using-stored-procedures-with-entity-framework-in-an-asp-net-application
http://beyondrelational.com/modules/2/blogs/64/posts/11620/entity-framework-40-bind-stored-procedure-with-result-entity-class.aspx

Monday, November 2, 2015

How to remove Source Control Binding from Visual Studio Project

If your project has been binding with TFS before, and you want to open the project locally, you will get following annoying information: The team foundation server http://some-tfs-server/ is currently not available, The solution will be opened locally. To remove the annoying information, deleted the .suo next to the .sln file, and then opened the .sln file in Notepad and deleted this entire section:
GlobalSection(TeamFoundationVersionControl) = preSolution
    SccNumberOfProjects = 2
    SccEnterpriseProvider = {xxxxx}
    SccTeamFoundationServer = http://some-tfs-server/
    SccLocalPath0 = .
    SccProjectUniqueName1 = xxDemo\\xxDemo.csproj
    SccProjectName1 = xxDemo
    SccLocalPath1 = xxDemo
EndGlobalSection
If you can connect to the TFS, you just want to simply unload the project from the source control server, go to File -> Source Control -> Change Source Control and then unbind and/or disconnect all projects and the solution.

This should remove all bindings from the solution and project files. (After this you can switch the SCC provider in Tools -> Options -> Source Control -> Plug-in Selection).

The SCC specification prescribes that all SCC providers should implement this behavior including VSS, TFS, etc.

Source:
http://stackoverflow.com/questions/358951/how-can-i-completely-remove-tfs-bindings

Wednesday, October 28, 2015

What's Breadcrumb on Web SIte?

Breadcrumb on  web site is a navigation menus which shows all position links from home page down to your current page. It offers tracking tools on which user can easily go back and would not get lost on big web sites  which host lots of contents.

Source:
http://www.hongkiat.com/blog/breadcrumb-menu-css3/

Monday, October 26, 2015

Best Bootstrap Plugins for Web BI and Reporting

Bootstrap is the best web front end framework designed for responsive design and mobile first. Except for standard Bootstrap functionality, there are lots of popular Bootstrap Plugins you can apply for your Web Reporting and BI requirement.

Fuel UX

is an incredible collection of enhancements to Twitter Bootstrap. All the controls are clean and lightweight, and they fit naturally into the bootstrap look and feel. The collection includes controls like datagrids, custom select boxes, spinners, trees, multi-step form wizards and more.
  1. Add the fueluxclass to a page wrapper (usually either <html> tag or <body> tag)
    <body class="fuelux">
  2. Include the CSS on your page somewhere:
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <link href="//www.fuelcdn.com/fuelux/3.11.5/css/fuelux.min.css" rel="stylesheet"> 
  3. Include the JS on your page somewhere:
    <!-- jQuery -->
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
    <script src="//www.fuelcdn.com/fuelux/3.11.5/js/fuelux.min.js"></script>
Fuel UX has an excellent datepicker, repeater, and tree control,

Date Range Picker

is a component creates a drop down from which you can select a range of date. The component relies on Bootstrap, JQuery, and Moments.js. You need to add following scripts and links on your page:
<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap/latest/css/bootstrap.css" />
 
<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
The Date Range Picker is attached to a text input. It will use the current value of the input to initialize, and update the input if new dates are chosen.
<input type="text" name="daterange" value="01/01/2015 - 01/31/2015" />
<script type="text/javascript">
$(function() {
    $('input[name="daterange"]').daterangepicker();
});
</script>

Clock Picker

is a unique clock style time picker for Bootstrap.
ClockPicker was designed for Bootstrap in the beginning. So Bootstrap and JQuery are the only dependencies.

The component only used .popover and some of .btn styles of Bootstrap.
<div class="input-group clockpicker">
    <input type="text" class="form-control" value="09:30">
    <span class="input-group-addon">
        <span class="glyphicon glyphicon-time"></span>
    </span>
</div>
<script type="text/javascript">
$('.clockpicker').clockpicker();
</script>

metisMenu

Stylish menu will give your website a perfect weapon to attract visitors. metisMenu can be a solution for this, it’s a JQuery based menu plugin for twitter Bootstrap 3. Here in this menu, you can give effects like animated accordion and supported with auto collapse system.
<script 
src="metisMenu.js"></script>
<script>
  $(function () {
    $('#menu').metisMenu();
  });
</script>

Bootstrap WYSIHTML5

A Javascript plugin that makes it easy to create simple WYSIWYG editors.

A file upload widget which features multiple file selection, drag and drop, progess bars, validation and preview images.
A JQuery plugin for validating forms within Bootstrap.


JQuery Pagination

A plugin that simplifies the usage of Bootstrap's Pagintion by using appropriate classes: .pagination, .active and .disabled.


Bootstrap Star Rating

A jQuery star rating plugin for Bootstrap that supports fractional star fill and RTL input support.

A JQuery based plugin for using select inputs with the multiple attributes.

Bootstrap Video Player

A customizable HTML5 video player plugin for jQuery based on Bootstrap's UI.

Data Tables

Data Tables is the most popular table enhancing add on for Bootstrap. This plugin not only makes your tables sort-able, but it also makes use of the framework’s pagination controls and makes the data searchable. This component is Web BI/Reporting must have tool.

Bootstrap Datagrid

bs_grid is a Bootstrap based jQuery Datagrid plugin. It comes with advanced row selection, pagination, sorting as well as filtering. This bs_grid is fully customizable, responsive, localization and Works sound with Bootstrap or individual.

Social Buttons

Chart.js

Chart.js (github) is a new charting library that uses the HTML5 canvas element and provides fallbacks for IE7/8. The library supports 6 chart types that are animated and fully customizable. Chart.js doesn’t have any dependencies and is less than 5kb in size. Say goodbye to flash!

Bootstrap Image Gallery

Bootstrap Image Gallery is a customizable image & video gallery extension to blueimp Gallery, a touch-enabled, responsive extension for images and videos in the modal dialog of the Bootstrap framework. It features swipe, mouse as well as navigation to keyboard, transition effects, fullscreen support and on-demand content loading. Bootstrap Image Gallery can be extended to display supplementary content types.

Source:
http://tutorialzine.com/2013/07/50-must-have-plugins-for-extending-twitter-bootstrap/
http://speckyboy.com/2014/06/16/plugins-for-extending-bootstrap/
https://medium.com/@themefisher/40-new-must-have-plugins-for-extending-twitter-bootstrap-possibilities-e2a79592c90b#.coqlx2gc7
http://tutorialzine.com/2013/04/50-amazing-jquery-plugins/

Friday, October 23, 2015

Bootstrap 3 Responsive Design Introduction

To add Bootstrap 3, insert following code to your web page.
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
Bootstrap requires HTML 5 doc type, so always put following at the beginning of your web page.
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8"> 
  </head>
</html>
Bootstrap is mobile first, to ensure proper rendering and zooming, put following at the beginning of your web page.
<meta name="viewport" content="width=device-width, initial-scale=1">
width=device-width sets the page width to screen width of the device. initial-scale=1 sets the initial zoom level when the page was first loaded.

Bootstrap divides screen size into 4 categories, and named with 4 classes accordingly.
  • Extra Small  < 768px       named with "xs"
  • Small            < 992px       named with "sm"
  • Medium        < 1200px     named with "md"
  • Large            >= 1200px   named with "lg"
Bootstrap used 2 types of containers to wrap all other web contents:
  • Fixed width container which has different fixed size for above 4 screens
<div class="container">
</div>
  • Full width container which takes up 100% of width regardless of screen size
<div class="container-fluid">
</div>
Note containers are not nestable, so you can't put container inside another container.

Following showed a basic Bootstrap web page:
<!DOCTYPE html>
<html lang="en">
<head>
  <title>Bootstrap Example</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
  <h1>My First Bootstrap Page</h1>
  <p>This is some text.</p> 
</div>
</body>
Bootstrap Grid System, one of the most powerful features, can create great responsive design for all kinds of screen.
  • Rows must be placed inside .container or .container-fluid for proper align and padding
  • Rows are used to create horizontal group of columns. 
  • The grid has maximum 12 columns for each row, thus any extra rows would be displayed in a new row. 
  • Each columns has padding, which are spacing between columns and can do align with other columns. 
Basic Structure of Bootstrap Grid:
<div class="container">
  <div class="row">
    <div class="col-*-*"></div>
  </div>
  <div class="row">
    <div class="col-*-*"></div>
    <div class="col-*-*"></div>
    <div class="col-*-*"></div>
  </div>
  <div class="row">
     ...  
  </div>
</div>
The first * could be xs, sm, md, lg, representing the 4 classes for different screen size, and the last * could be 1,2,3,4. The last * adds up should be always 12.

Example of Bootstrap Grid:
<div class="container">
  <div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
    <div class="col-md-2"></div>
  </div>
  <div class="row">
    <div class="col-sm-8"></div>
    <div class="col-sm-4"></div>
  </div>
  <div class="row">
     ...  
  </div>
</div>
The first row of columns will be stacked when  the screen size is less than 992px. The second row of columns will be stacked when the screen size is less than 768px.

Note the 4 different classes for different screen size can be combined together to create more flexible layout.

For example, for following code, if the screen is big enough, all will be displayed in one row. However, if the screen get smaller, col-sm-4 will be useless, and all col-xs-6 will be effective, and the last column will be displayed in another row.
<div class="row">
  <div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
  <div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
  <div class="col-xs-6 col-sm-4">.col-xs-6 .col-sm-4</div>
</div>
Bootstrap table has following classes:
.table .tablestrip .table-bordered .table-hover .table-condensed  .table-responsive

The .tablestrip adds zebra strips to a table.
The .table-bordered adds borders for all sides of the table and cells.
The .table-hover enables hover states on each row.
The .table-condensed makes a table more compact through reduce the cell padding by half.
The .table-responsive makes table scroll horizontally on devices with small screen. Note it should be used with <div> outside the table.

<div class="table-responsive">
  <table class="table tablestrip table-bordered table-hover table-condensed">
    ...
  </table>
</div>
Bootstrap table row and column has following classes:
.active .success .info .warning .danger
.active adds hover color to table cells.
<tr class="success">
  <td>John</td>
  <td>Doe</td>
  <td>john@example.com</td>
</tr>
Bootstrap will let some elements show or hide, depending on the screen size:

Images can scale based on screen size by using .img-responsive class. The image will be scale while keep its aspect ratio. To center responsive image, using .center-block class.

Source:
http://getbootstrap.com/css/
http://www.w3schools.com/bootstrap/bootstrap_get_started.asp
http://www.w3schools.com/bootstrap/bootstrap_grid_system.asp
http://www.devx.com/webdev/easily-create-responsive-websites-using-bootstrap.html