Localization and bit of SEO

Internet is widely available worldwide no matter what language they may speak.

 

Then, why not make your website in multi languages?

 

ASP.Net come with great feature called resource files where you can store key and value per languages and locale (culture) you specify.

The use of resource file is straight forward and easy to implement.  But working with routing feature and making it SEO friendly takes few extra steps

 

and here is how.

Continue reading “Localization and bit of SEO”

Coding Rule

My memo;

Just so we can have more easy to read code by having coding rules; here is mine.

Naming

local and only local variable is usually single letter or very short ones like, a, b, c, x etc.

Input variable names start with lower letter, full name, capital letter if it consist of more than 2 words, like isGood, nameOfFunction.

My own class names are all lower case, even if it is consists of more than 2 words.  Variable inside of classes have Capital letter starting like, City, Name, NameOfFunction etc.

 

 

 

Tips: Designing Views and Using Bootstrap

When you create MVC project with Visual Studio, by default Bootstrap is ready to use.  Bootstrap is mobile friendly CSS, ready to use out of the box. If you are not ultra picky about design, I recommend to use it.  And even if you are, you can still use Bootstrap as a base and make great views.

Here is my memo for design Views.

Bootstrap is mobile first design, so do design in mobile mode first, then create desktop / tablet design using media specific customizes CSS properties.

Example below, if the screen width is more than 768px, then apply this CSS properties, which give 150px padding at top.

for less (and more screen sizes)

 

Reference:

Bootstrap http://getbootstrap.com/

ASP.Net Web API 2 and AMCHARTS

Amcharts is one of the best js base chart service out there today.   Amcharts takes JSON data and display all sorts of neat charts.  Here, I am generating JSON data through ASP.Net Web API 2 and show AmCharts graphs.

I followed tutorial document from Amcharts (https://www.amcharts.com/tutorials/using-data-loader-to-connect-charts-to-mysql-data-base/).  This tutorial goes over how to query data from mySQL then generate JSON data then display charts in PHP, but we don’t have to worry about MySQL or PHP, we just create and fetch JSON data from API and goes from there.

First, we will have to know what type of data you want to generate.  We can generalize shape of data we want to work with.  Graphs usually are generated from table of data (or in this case JSON data that fits in table).  If you are to work with 2D graphs, then we will need to generate 2 dimensions of data, x and y. And that’s what we do today.

Let’s start with something simple.  I have system log stored in my DB,  X being time, call it category, Y being some value of some log properties, call it value1 and value2.

Continue reading “ASP.Net Web API 2 and AMCHARTS”

Using Cache in ASP.Net MVC

If you want to make your pages faster to load, you can make use of Cache by using Cache filter.

If you simply want to add Cache capability for a one page, then add

This will give you 120 seconds of cache.

If you want to manage cache for multiple pages, then I recommend creating profiles and manage it at Web.config like below,

then calling these profiles like below;

You can read more detail at : https://msdn.microsoft.com/en-us/library/system.web.mvc.outputcacheattribute(v=vs.118).aspx

Trying to get first letter of string in Linq

My error today;

LINQ to Entities does not recognize the method ‘Char get_Chars(Int32)’ method, and this method cannot be translated into a store expression.

I was trying to get list of records that matches fist letter of string.  But I guess it’s not as simple as just

but this worked.

 

Setting DisplayFormat at Model

You can set how you want to format your data at Model level by using DisplayFormat. It is simple yet deep and worthy to master.

Microsoft put documents here:

Typically when you have numerical value in your database, it is stored like “123123121”.  But I want to show it like “123,123,121” for better readability, then simply make your model like below;

You can format at view level too, but if you are using one model at multiple views and you want all views to have them in same format, this is better.

DisplayFormat for date and time

If you need to know more about date time format please read: https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx