January 14, 2014

Custom CMS Applications in Asp.net Web Forms / MVC

Rion Williams shared his ideas on Asp.Net forum related to Custom CMS Application in Asp.Net as:

I can't recommend the Orchard CMS enough. It has a tremendous community, an expansive set of modules that cover nearly everything that you can think of and it built completely using .NET, MVC and the Razor View Engine and contains modules for just about everything : 

Common modules include : 

If you come from a .NET background, I highly suggesting giving it a look (even if it isn't for this project). But, as far as Web Forms specific, you'll likely need to look at one of the following choices :

Consider trying out each of the above suggestions to see which ones that you prefer and suits your needs the best as with most things there is never a single "perfect" solution.

Difference between WCF And Web Api

To whom choose between WCF or WEB API

1. Choose WCF when you want to create a service that should support special scenarios such as one way messaging, message queues, duplex communication etc.

2. Choose WCF when you want to create a service that can use fast transport channels when available, such as TCP, Named Pipes, or maybe even UDP (in WCF 4.5), and you also want to support HTTP when all other transport channels are unavailable.

3. Choose Web API when you want to create a resource-oriented services over HTTP that can use the full features of HTTP (like URIs, request/response headers, caching, versioning, various content formats).

4. Choose Web API when you want to expose your service to a broad range of clients including browsers, mobiles, iPhone and tablets.

Hope it helps you. Let me know if any query remains.

January 10, 2014

Manage Multiple Buttons in MVC 4

In Asp.Net MVC, we have controllers, views and model architecture which are free from server side controls which really helps application to runs faster than web form application whom have the series of server controls. Here we have to choose our engine and In this post I choose Razor engine

Many developers now a days ask questions on Asp.net forum about "How to manage the multiple button post functionality and perform different variety of functionality upon each button click". In web form, this is quite easy for any person but in MVC you have to declare the multiple partial views to fix this need.

But instead of going to use partial view approach, we have another approach is also present known as "Client-side approach" in which we create a JavaScript functionality with a parameter named like "buttonType" and in this function we actual redirect the request to controller/method-name/parameter value.

@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
    
    function PerformFunctionalityByValue(buttonType) {
        var customerId = @Model.CustomerId;
        window.location.href = "/Home/PerformFunctionalityByValue?id=" + 
               customerId + "&type=" + buttonType;
    }

    function BackToDefault() {
        window.location.href = '/Home/Index/';
    }
    
</script>

<fieldset>
        <legend>@ViewBag.Title</legend>

            <div class="controls">
                <input type="button" value="Button A" class="btn btn-primary" 
                    onclick=" return PerformFunctionalityByValue('ButtonA'); " 
                    style="width: 430px;" />
            </div>

            <div class="controls">
                <input type="button" value="Button B" class="btn btn-primary" 
                    onclick=" return PerformFunctionalityByValue('ButtonB'); " 
                    style="width: 430px;" />
            </div>

            <div class="controls">
                <input type="button" value="Button C" class="btn btn-primary" 
                    onclick=" return PerformFunctionalityByValue('ButtonC'); " 
                    style="width: 430px;" />
            </div>

            <div class="controls">
                <input type="button" value="Back to Home page" class="btn btn-primary" 
                    onclick=" return BackToDefault(); " style="width: 430px;" />
            </div>

</fieldset>

In controller method, we create different regions with respect to parameter value and performs the desire functionality in it.

public ActionResult PerformFunctionalityByValue(long id = 0, string type = "")
{
    if (type == "ButtonA")
    {
        // Perform the Button A functionality there
        // And redirect to your specific view or skip this line
    }
    else if (type == "ButtonB")
    {
        // Perform the Button B functionality there
        // And redirect to your specific view or skip this line
    }
    else if (type == "ButtonC")
    {
        // Perform the Button C functionality there
        // And redirect to your specific view or skip this line
    }

    return RedirectToAction("Index", "Home");
}

That's the fastest and easiest approach instead of creating the multiple partial views. Hope this will help you to understand the flow and logic. Stay tuned!

January 8, 2014

18 Useful Life Hacks For Your Health

Apmayy wrote the important points that are useful life hacks for your life. In this post, I'm sharing few useful points which helps anybody to stay sharp and active in their routine life.

  1. 30 minutes of exercise can make you 10% smarter.
  2. Drinking half a glass of water before bed and half a glass when waking up can serve as a psychological cue to remember all your dreams.
  3. Don't wet your toothbrush after you put toothpaste. Water will reduce the healthy benefits of toothpaste.
  4. Lemon juice with a pinch of salt (warm) every morning lowers the cholesterol levels and brings down your weight.
  5. Fifteen straights minutes of laughter has the same health benefits as 30 mins of sit ups.
  6. Health benefits of Green Tea: (a). Reduce cavity risks. (b). Strengthen bones. (c). Weight loss. (d). Reduces cancer risk.
  7. Exhale an alternate feet while running to avoids cramp. This prevents adding extra stress to one side of your body.
  8. Eating salmon (a specie of fish) can help your hair grow faster.
  9. Drinking black tea can help prevent lung damage cause by smoking.
  10. If you trying to get rid of smoking in a room, spin a wet towel around.
  11. Cauliflower dipped in BBQ sauces tastes almost the same as chicken nuggets and it is infinitely healthier.
  12. Chewing the same flavour of gum when taking a test as you did when study will improve your memory.
  13. You are 47% more likely to live an extra decade if you eat home-cooked meals five times a week.
  14. Whenever you get burned, apply the toothpaste it soothes the pain and stops the burning.
  15. Lack of sleep can cause you to gain weight.
  16. Smiling naturally lifts the muscles in the face and slow the down the rate at we age.
  17. Your phone emits a radiations that's 1000 times stronger when battery is low. Avoid answering it when this is the case.
  18. If you drink more water during day, your body has less effort to do at night. It means you have less sleep if you're well hydrated.

January 7, 2014

Stay Sharp in Daily Life

Junaid Tahir explains excellent thought about how to Stay Sharp in your daily life. I liked his example and sharing here just to help others.

Once upon a time a very strong woodcutter asked for a job in a timber merchant, and he got it. The pay was really good and so were the work conditions. For that reason,the woodcutter was determined to do his best.

His boss gave him an axe and showed him the area where he was supposed to work. The first day, the woodcutter brought 18 trees.

Congratulations,” the boss said. “Go on that way!” Very motivated for the boss’ words, the woodcutter try harder the next day,but he only could bring 15 trees. The third day he try even harder, but he only could bring 10 trees. Day after day he was bringing less and less trees.

I must be losing my strength”, the woodcutter thought. He went to the boss and apologized, saying that he could not understand what was going on.

When was the last time you sharpened your axe?” the boss asked. “Sharpen? I had no time to sharpen my axe. I have been very busy trying to cut trees.”

Our lives are like that. We sometimes get so busy that we don’t take time to sharpen the axe.” In today’s world, it seems that everyone is busier than ever, but less happy than ever. Why is that? Could it be that we have forgotten how to stay sharp?

There’s nothing wrong with activity and hard work. But God doesn’t want us to get so busy that we neglect the truly important things in life, like taking time to pray, to read. We all need time to relax, to think and meditate, to learn and grow.

If we don’t take time to sharpen the axe, we will become dull and lose our effectiveness. So start today. Think about the ways by which you could do your job more effectively and add a lot of value to it.

January 6, 2014

Joins in C# Linq

There are four types of sql joins which are using in LINQ query for querying the data. In this post, I'm going to show you the working JOIN operator in LINQ which behaves as SQL JOIN. Normally we have four types of Joins.

==============
1. INNER JOIN
==============

Returns only those records which are exists in both tables.

var innerJoin = (from product in _dataContext.Products
                join order in _dataContext.Orders 
                     on product.ProductId equals order.ProductId
                order by order.OrderDate
                select new
                {
                   order.OrderId,
                   product.ProductId,
                   product.ProductName,
                   product.UnitPrice,
                   order.Quantity,
                   order.Price
                }).ToList();

===================
2. LEFT OUTER JOIN
===================

Returns all records from left table and only matches records from right table.

var leftJoin = (from product in _dataContext.Products
                join order in _dataContext.Orders 
                     on product.ProductId equals order.ProductId
                     into query from joinedTable in query.DefaultIfEmpty()
                order by product.ProductName
                select new
                {
                   OrderId = (int?)joinedTable.OrderId,
                   product.ProductId,
                   product.ProductName,
                   product.UnitPrice,
                   Quantity = (int?)joinedTable.Quantity,
                   Price = (decimal?)joinedTable.Price
                }).ToList();

==============
3. CROSS JOIN
==============

Returns the records that are the multiplication of rows from table A to table B.

var crossJoin = from product in _dataContext.Products
                from order in _dataContext.Orders
                select new
                {
                   order.OrderId,
                   product.ProductId,
                   product.ProductName,
                   order.OrderDate
                };

==============
4. GROUP JOIN
==============

It groupes the collection of objects into seprate collections and then matches the collection with each other. Returns an empty array if right collection doesn't match any element with left collection.

var groupJoin = (from product in _dataContext.Products
                join order in _dataContext.Orders 
                     on product.ProductId equals order.ProductId into query
                order by order.OrderDate
                select new
                {
                   Order = query,
                   product.ProductId,
                   product.ProductName,
                   product.UnitPrice,
                   order.Quantity,
                   order.Price
                }).ToList();

Hope you understand now the different SQL JOINs and how to use them in your programming areas.