Improve Your Technology

Just another blog for techology

Is MVC architecture a necessity?

If you ask me, “Is MVC architecture a necessity?” my answer is simple, “No”. There are many reasons from my personal experience. Every architectural design pattern describes about the situations where the particular pattern should be used. It just describes the type of situation and the advantages of using the architecture but never tells the architecture that you should follow for a situation.

 Web Application point of view

 In .NET we have code behind files. The main purpose of this code behind files is to maintain business logic regarding a particular page at one place, to compile them only once. The intention of code behind files goes with reducing execution time of web pages. When we are using code behind concept we face problem of file organization. So, some of the companies didn’t show interest in code behind concept.  Here the main purpose of designing code behind files is lost.

 When organization is not ready to maintain more number of files because of their constraints then they are moving towards writing everything in DLLs and calling these functions from various ASPX pages. With this concept they are able to compile entire business logic at the time of deployment and reducing number of files to maintain.

 In the above scenario the ASPX pages contains user interface controls and small code to call compiled functions (DLLs) in order to perform logical operations on the ASPX page. As there is no much code involved on ASPX page it won’t take much time to compile.

 I personally feel this is one type of system architecture to get better performance. So, my sincere suggestion is, study concepts and utilize them in your customized manner.


September 10, 2009 Posted by | ASP.NET MVC, Is MVC architecture a necessity?”, Technology, Uncategorized | | Leave a comment

DateDiff and DateAdd in C#

When I started working on C# date functions I felt deficult. As I am a VB developer never worried about these type of small things.  I don’t know why in C# these functionality not provided. So I prepared myself a class file which can handle basic date functions that exists in VB. Below I provided code for this. I think it can useful for some of the people.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System;
using System.Collections.Generic;
using System.Text;

namespace CustomDate
    public enum DateInterval

    public class DateAndTime
        public static long DateDiff(DateInterval interval, DateTime dt1, DateTime dt2)
            return DateDiff(interval, dt1, dt2, System.Globalization.DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek);

        private static int GetQuarter(int nMonth)
            if (nMonth <= 3)
                return 1;
            if (nMonth <= 6)
                return 2;
            if (nMonth <= 9)
                return 3;
            return 4;

        public static DateTime DateAdd(DateInterval interval, DateTime dt, Int32 val)
            if (interval == DateInterval.Year)
                return dt.AddYears(val);
            else if (interval == DateInterval.Month)
                return dt.AddMonths(val);
            else if (interval == DateInterval.Day)
                return dt.AddDays(val);
            else if (interval == DateInterval.Hour)
                return dt.AddHours(val);
            else if (interval == DateInterval.Minute)
                return dt.AddMinutes(val);
            else if (interval == DateInterval.Second)
                return dt.AddSeconds(val);
            else if (interval == DateInterval.Quarter)
                return dt.AddMonths(val * 3);
                return dt;

        public static long DateDiff(DateInterval interval, DateTime dt1, DateTime dt2, DayOfWeek eFirstDayOfWeek)
            if (interval == DateInterval.Year)
                return dt2.Year – dt1.Year;

            if (interval == DateInterval.Month)
                return (dt2.Month – dt1.Month) + (12 * (dt2.Year – dt1.Year));

            TimeSpan ts = dt2 – dt1;

            if (interval == DateInterval.Day || interval == DateInterval.DayOfYear)
                return Round(ts.TotalDays);

            if (interval == DateInterval.Hour)
                return Round(ts.TotalHours);

            if (interval == DateInterval.Minute)
                return Round(ts.TotalMinutes);

            if (interval == DateInterval.Second)
                return Round(ts.TotalSeconds);

            if (interval == DateInterval.Weekday)
                return Round(ts.TotalDays / 7.0);

            if (interval == DateInterval.WeekOfYear)
                while (dt2.DayOfWeek != eFirstDayOfWeek)
                    dt2 = dt2.AddDays(-1);
                while (dt1.DayOfWeek != eFirstDayOfWeek)
                    dt1 = dt1.AddDays(-1);
                ts = dt2 – dt1;
                return Round(ts.TotalDays / 7.0);

            if (interval == DateInterval.Quarter)
                double d1Quarter = GetQuarter(dt1.Month);
                double d2Quarter = GetQuarter(dt2.Month);
                double d1 = d2Quarter – d1Quarter;
                double d2 = (4 * (dt2.Year – dt1.Year));
                return Round(d1 + d2);

            return 0;


        private static long Round(double dVal)
            if (dVal >= 0)
                return (long)Math.Floor(dVal);
            return (long)Math.Ceiling(dVal);

Let me know if you need any date functions or enhancements in existing functions.

September 9, 2009 Posted by | C#, DateDiff and DateAdd in C#, Technology, Uncategorized | | 4 Comments