Example #1
0
        public ActionResult Index(int[] projectId, int[] userId, int[] taskId, string date, int?isArchived, string label, string text, string sortBy, string sortOrder)
        {
            var model = new HourIndexModel();

            model.Tab          = "Hour";
            model.FindText     = text;
            model.FindCategory = "Hour";

            model.Projects           = DataHelper.GetProjectList();
            model.ProjectId          = projectId ?? new int[0];
            model.ProjectName        = DataHelper.ToString(model.Projects, model.ProjectId, "any project");
            model.ProjectDisplayName = DataHelper.Clip(model.ProjectName, 40);

            model.Users           = DataHelper.GetUserList();
            model.UserId          = userId ?? new int[0];
            model.UserName        = DataHelper.ToString(model.Users, model.UserId, "any user");
            model.UserDisplayName = DataHelper.Clip(model.UserName, 20);

            model.Label      = label;
            model.Date       = date ?? string.Empty;
            model.IsArchived = isArchived ?? 1;

            model.Filters = MyService.FilterFetchInfoList("Hour");

            model.SortBy    = sortBy ?? "Date";
            model.SortOrder = sortOrder ?? "DESC";
            model.SortableColumns.Add("Date", "Date");
            model.SortableColumns.Add("ProjectName", "Project");
            model.SortableColumns.Add("UserName", "User");

            model.LabelByCountListModel =
                new LabelByCountListModel
            {
                Action = "Hour",
                Label  = label,
                Labels = DataHelper.GetTaskLabelByCountList()
            };

            var criteria = new HourCriteria()
            {
                ProjectId  = projectId,
                UserId     = userId,
                TaskId     = taskId,
                Date       = new DateRangeCriteria(model.Date),
                IsArchived = DataHelper.ToBoolean(isArchived, false),
                TaskLabels = string.IsNullOrEmpty(label) ? null : new[] { label },
                Text       = text
            };

            var hours = HourService.HourFetchInfoList(criteria)
                        .AsQueryable();

            hours = hours.OrderBy(string.Format("{0} {1}", model.SortBy, model.SortOrder));

            model.Hours = hours;

            return(this.View(model));
        }
        public ActionResult Index(int?year, int?userId)
        {
            var model    = new HourIndexModel();
            var projects = ProjectRepository.ProjectFetchInfoList();

            model.UserId = userId ?? ((IBusinessIdentity)Csla.ApplicationContext.User.Identity).UserId;

            var weeks = WeekCollection.GetWeeks(year ?? DateTime.Now.Year);

            model.Weeks = weeks;

            var criteria =
                new HourDataCriteria
            {
                Date   = CriteriaHelper.ToDateRangeCriteria(weeks.StartDate, weeks.EndDate),
                UserId = model.UserId
            };

            var hours = HourRepository.HourFetchInfoList(criteria);

            model.Hours = hours;

            model.Year = year ?? DateTime.Now.Year;

            var years = new List <int>();

            for (var currentYear = year ?? DateTime.Now.Year; currentYear <= DateTime.Now.Year; currentYear++)
            {
                years.Add(currentYear);
            }

            model.Years = years;

            var users = UserRepository.UserFetchInfoList(projects);

            model.Users = users;

            return(this.View(model));
        }