public ActionResult Add()
        {
            Business.ApplicationService.AppServiceClient appclient = new Business.ApplicationService.AppServiceClient();
            List<customweek> weekcollection = UI.Utilities.DateTimeUtility.GetWeeks(DateTime.Now.Month, DateTime.Now.Year);
            customweek editingweek = new customweek();

            int year = DateTime.Now.Year;
            int month = DateTime.Now.Month;
            int week = 1;

            try
            {
                year = Convert.ToInt32(Request.QueryString["year"].ToString());
                month = Convert.ToInt32(Request.QueryString["month"].ToString());
                week = Convert.ToInt32(Request.QueryString["week"].ToString()) - 1;
                weekcollection = UI.Utilities.DateTimeUtility.GetWeeks(month, year);
                editingweek = weekcollection[week];
            }
            catch
            {
                foreach (customweek wk in weekcollection)
                {
                    if (wk.isCurrentweek)
                    {
                        editingweek = wk;
                    }
                }
            }

            return View(editingweek);
        }
        public static List <customweek> GetWeeks(int month, int year)
        {
            var calendar       = System.Globalization.CultureInfo.CurrentCulture.Calendar;
            var firstDayOfWeek = DayOfWeek.Monday;//System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek = ;
            var weekPeriods    =
                Enumerable.Range(1, calendar.GetDaysInMonth(year, month))
                .Select(d =>
            {
                var date          = new DateTime(year, month, d);
                var weekNumInYear = calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, firstDayOfWeek);
                return(new { date, weekNumInYear });
            })
                .GroupBy(x => x.weekNumInYear)
                .Select(x => new { DateFrom = x.First().date, To = x.Last().date })
                .ToList();
            List <customweek> weektimeset = new List <customweek>();

            for (int i = 0; i < weekPeriods.Count; i++)
            {
                customweek tempweek = new customweek();
                tempweek.weeknumber     = i;
                tempweek.startdate      = weekPeriods[i].DateFrom;
                tempweek.enddate        = weekPeriods[i].To;
                tempweek.year           = weekPeriods[i].DateFrom.Year;
                tempweek.month          = weekPeriods[i].DateFrom.Month;
                tempweek.monthname      = ToShortMonthName(weekPeriods[i].DateFrom.Month);
                tempweek.dayscollection = getdatesbetweendates(weekPeriods[i].DateFrom, weekPeriods[i].To);
                tempweek.days           = tempweek.dayscollection.Count;

                if (DateTime.Now.Day >= weekPeriods[i].DateFrom.Day && DateTime.Now.Day <= weekPeriods[i].To.Day)
                {
                    tempweek.isCurrentweek = true;
                }

                weektimeset.Add(tempweek);
            }
            return(weektimeset);
        }
        public ActionResult Edit()
        {
            Business.ApplicationService.AppServiceClient appclient = new Business.ApplicationService.AppServiceClient();
            List<customweek> weekcollection = UI.Utilities.DateTimeUtility.GetWeeks(DateTime.Now.Month, DateTime.Now.Year);
            customweek editingweek = new customweek();

            int year = DateTime.Now.Year;
            int month = DateTime.Now.Month;
            int week = 1;

            try
            {
                year = Convert.ToInt32(Request.QueryString["year"].ToString());
                month = Convert.ToInt32(Request.QueryString["month"].ToString());
                week = Convert.ToInt32(Request.QueryString["week"].ToString()) - 1;
                weekcollection = UI.Utilities.DateTimeUtility.GetWeeks(month, year);
                editingweek = weekcollection[week];
            }
            catch
            {
                foreach (customweek wk in weekcollection)
                {
                    if (wk.isCurrentweek)
                    {
                        editingweek = wk;
                    }
                }
            }
            userdashboardtimesheet usermonthlydashboardtimesheet = new userdashboardtimesheet();
            Business.ApplicationService.appuser dashboarduser = appclient.GetUserObject(Session["usertoken"].ToString());

            usermonthlydashboardtimesheet.User = dashboarduser;
            usermonthlydashboardtimesheet.timesheetmonth = UI.Utilities.DateTimeUtility.ToLongMonthName(editingweek.month);
            usermonthlydashboardtimesheet.timesheetsstartdate = editingweek.startdate.ToShortDateString();
            usermonthlydashboardtimesheet.timesheetenddate = editingweek.enddate.ToShortDateString();

            List<AppWeekTimeSheet> weektimesheetscollection = new List<AppWeekTimeSheet>();

            AppWeekTimeSheet dashboarddata = new AppWeekTimeSheet();

            dashboarddata.timesheetweek = editingweek;

            Business.ApplicationService.timesheet[] timesheets = appclient.Gettimesheets(Session["companyid"].ToString(), "", "", "", editingweek.startdate.ToString("yyyy-MM-dd hh:mm:ss"), editingweek.enddate.ToString("yyyy-MM-dd hh:mm:ss"));
            UI.testmodel.timesheet singletimesheet = new UI.testmodel.timesheet();
            if (timesheets.Length > 0)
            {
                UI.testmodel.timesheet objsheet = Newtonsoft.Json.JsonConvert.DeserializeObject<UI.testmodel.timesheet>(timesheets[0].data);
                dashboarddata.timesheetid = timesheets[0].id;
                dashboarddata.weektimesheetdata = objsheet;
            }
            weektimesheetscollection.Add(dashboarddata);

            usermonthlydashboardtimesheet.weektimesheets = weektimesheetscollection;
            return View(usermonthlydashboardtimesheet);
        }
        public static List<customweek> GetWeeks(int month,int year)
        {
            var calendar = System.Globalization.CultureInfo.CurrentCulture.Calendar;
            var firstDayOfWeek = DayOfWeek.Monday;//System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek = ;
            var weekPeriods =
            Enumerable.Range(1, calendar.GetDaysInMonth(year, month))
                      .Select(d =>
                      {
                          var date = new DateTime(year,month, d);
                          var weekNumInYear = calendar.GetWeekOfYear(date, CalendarWeekRule.FirstDay, firstDayOfWeek);
                          return new { date, weekNumInYear };
                      })
                      .GroupBy(x => x.weekNumInYear)
                      .Select(x => new {DateFrom = x.First().date, To = x.Last().date })
                      .ToList();
            List<customweek> weektimeset = new List<customweek>();

            for (int i = 0; i < weekPeriods.Count;i++)
            {
                customweek tempweek = new customweek();
                tempweek.weeknumber = i;
                tempweek.startdate = weekPeriods[i].DateFrom;
                tempweek.enddate = weekPeriods[i].To;
                tempweek.year = weekPeriods[i].DateFrom.Year;
                tempweek.month = weekPeriods[i].DateFrom.Month;
                tempweek.monthname = ToShortMonthName(weekPeriods[i].DateFrom.Month);
                tempweek.dayscollection = getdatesbetweendates(weekPeriods[i].DateFrom, weekPeriods[i].To);
                tempweek.days = tempweek.dayscollection.Count;

                if (DateTime.Now.Day >= weekPeriods[i].DateFrom.Day && DateTime.Now.Day <= weekPeriods[i].To.Day)
                {
                    tempweek.isCurrentweek = true;
                }

                weektimeset.Add(tempweek);
            }
            return weektimeset;
        }