Friday, November 20, 2015
Tuesday, November 17, 2015
CSS background Stretch
Set the background-size property to the element.
body {
background-size: 100% auto;
}
body {
background-size: 100% auto;
}
Sunday, November 15, 2015
Asp.net MVC - Application Architecture
Don't directly call your database in controller.
In your Asp.net MVC Application, you should not place your database logic inside your controller actions. Mixing your database and controller logic makes your application more difficult to maintain over time. It is recommended that you place your database logic in separate repository layer.
Don't directly call your repository in controller.
You should create another separate layer called service layer or business logic layer, and put your application business logic. roles and validations. Service layer communicates with the repository layer, process the data into information and pass it the controller.
Don't coupled your service layer with controller.
You should isolate your service layer with controller. Service layer must be in-depended, means it should not depended on the plate-form depended objects. So any application can use it without worrying about frame-work version and plate-form.
for example: The service layer should be able to use in WinForms , WebForms , WPF or Asp.net MVC Applications.
Don't put your UI Logic in controller.
UI may have some kind of logic, such as, display the user panel if the user is logged In, show/hide buttons, show the publish button if the publisher is logged in and so on. This logic may have several conditions, functions and properties, We should avoid to put the UI logic directly in our controller because controller is not responsible for handling the logic, but the application flow.
Mixing your application flow and UI/Business logic makes more difficult to maintain your application. We should separate our UI Logic in form of view models, and view models should be called by controller.
Controller is responsible for taking the input from user and pass it to the view models, view model take the input from controller, apply some UI logic if needed, and pass it to he service layer, service layer process it and pass it to repository, and repository is responsible for manipulate the database.
Friday, November 13, 2015
Posting JSON data to WebAPI Always Null
I was playing with the JQuery and WebAPI and posting some data in JSON format to the Action.
In the Post Action of WebApi Controller [FormBody] Attributes catches the data, and we cast it in our respective type. I felt that send data in JSON / JSON.stringify() so i must be cast in String type. but i get my data always null?
After several tries i changed the string type to dynamic and it solved my problem! :)
public void Post([FromBody]dynamic value)
{
}
In the Post Action of WebApi Controller [FormBody] Attributes catches the data, and we cast it in our respective type. I felt that send data in JSON / JSON.stringify() so i must be cast in String type. but i get my data always null?
After several tries i changed the string type to dynamic and it solved my problem! :)
public void Post([FromBody]dynamic value)
{
}
Uncaught Error: [$injector:modulerr] AngularJS Error in console - Google Chrome.
While using routing in AngularJS, sometime we face this error in our console.
Uncaught Error: [$injector:modulerr]
The problem was caused by missing inclusion of ngRoute module.
Reference this link to your page may solve this problem.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
Uncaught Error: [$injector:modulerr]
The problem was caused by missing inclusion of ngRoute module.
Reference this link to your page may solve this problem.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>
Wednesday, November 11, 2015
SignalR - Simple Implementation.
SignalR is an API Provided by Asp.net used in web applications to build real time push functionalities and "Push" content to the connected clients.
It's very simple and easy to install SignalR in your application by visual studio 2012.
1: Go to the Visual Studio Tools > NuGet Package Manager > Manage NuGet Package for Solution.
2: Type SignalR in Search Filed.
After installation, you will get these libraries in your Scripts folder.
3: Reference the jQuery library in your webpage.
<script src="Scripts/jquery-1.6.4.min.js" ></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
4: Create a C# Class and inherits with Hub Class.
// Server Code.
public class MessageHub : Hub
{
public void Send(string name, string message)
{
Clients.All.broadcastMessage(name, message);
}
}
Here we have two methods. One is "Send" and other is Client.All.broadcastMessage();
"Send" Method is defined on the Server and will be consumed by client. and broadcastMessage Method will be defined on the client. when the client call the Send Method broadcastMessage will be invoked on the every connected clients.
5: Initialize MessageHub Class on Client.
// Client code.
<script>
var chat = $.connection.messageHub;
chat.client.broadcastMessage = function (name, message) {
alert(name + " Said: " + message );
};
$.connection.hub.start().done(function () {
$("#btn" ).click(fucntion(){
chat.server.send("Zeeshan", "Hello All");
});
});
</script>
First line; creates a reference of a server MessageHub.cs Class. Make sure it must be in camel case means first latter must be small.
Second line; declares a function on the client which will be invoked by the "Send" Method declared on the Server.
When ever a user visits a webpage which is implemented with SignalR.
$.connection.hub.start().done(function(){}) event automatically fires and indicate that a new connection is stared.
It takes a function as a parameter in done() function and enable us to call server methods inside it. "Server method must be in camel case on client."
When user will press the button "#btn", the name and message will be broadcast to the all connected users.
This the very simple example, use this code in your own manner.
It's very simple and easy to install SignalR in your application by visual studio 2012.
1: Go to the Visual Studio Tools > NuGet Package Manager > Manage NuGet Package for Solution.
2: Type SignalR in Search Filed.
After installation, you will get these libraries in your Scripts folder.
3: Reference the jQuery library in your webpage.
<script src="Scripts/jquery-1.6.4.min.js" ></script>
<!--Reference the SignalR library. -->
<script src="Scripts/jquery.signalR-2.1.0.min.js"></script>
<!--Reference the autogenerated SignalR hub script. -->
<script src="signalr/hubs"></script>
4: Create a C# Class and inherits with Hub Class.
// Server Code.
public class MessageHub : Hub
{
public void Send(string name, string message)
{
Clients.All.broadcastMessage(name, message);
}
}
Here we have two methods. One is "Send" and other is Client.All.broadcastMessage();
"Send" Method is defined on the Server and will be consumed by client. and broadcastMessage Method will be defined on the client. when the client call the Send Method broadcastMessage will be invoked on the every connected clients.
5: Initialize MessageHub Class on Client.
// Client code.
<script>
var chat = $.connection.messageHub;
chat.client.broadcastMessage = function (name, message) {
alert(name + " Said: " + message );
};
$.connection.hub.start().done(function () {
$("#btn" ).click(fucntion(){
chat.server.send("Zeeshan", "Hello All");
});
});
</script>
First line; creates a reference of a server MessageHub.cs Class. Make sure it must be in camel case means first latter must be small.
Second line; declares a function on the client which will be invoked by the "Send" Method declared on the Server.
When ever a user visits a webpage which is implemented with SignalR.
$.connection.hub.start().done(function(){}) event automatically fires and indicate that a new connection is stared.
It takes a function as a parameter in done() function and enable us to call server methods inside it. "Server method must be in camel case on client."
When user will press the button "#btn", the name and message will be broadcast to the all connected users.
This the very simple example, use this code in your own manner.
Tuesday, November 10, 2015
Recursion Algorithm
In computer science, Recursion is a function that calls itself.
Recursive function has two main points. one is the stopping point and
second is calling itself until problem is solved.
This is the most common example of returning a factorial of given input parameter
by recursive function.
int factorial(int n) {
if (n == 0)
return 1;
else
return (n * factorial(n-1));
}
Subscribe to:
Comments (Atom)
