示例#1
0
文件: DemoData.cs 项目: mamboer/itask
        public List<Task> GetAll(string gid,DateTime sTime,DateTime eTime)
        {
            User userservice = new User(this.uow);
            List<User> users = userservice.GetAll();

            var rd = new Random();

            //随机用户
            Func <User> fnRandomUser = () =>
                                {
                                    var cnt = users.Count;
                                    cnt = rd.Next(cnt);
                                    return users[cnt];
                                };

            //随机时间
            Func<DateTime> fnRdDate = () => sTime.AddDays(rd.Next(7));

            var taskBiz = new Task(this.uow);
            var tasks = taskBiz.GetAll(gid, DateTime.Parse("2011-11-01"), DateTime.Parse("2011-12-01"));

            tasks.ForEach(x=>
                          	{
                          		x.UserId = fnRandomUser().Id;
                          		x.CreatedAt = fnRdDate();
                          	});

            return tasks;
        }
示例#2
0
        /// <summary>
        /// Action Index
        /// </summary>
        /// <param name="ddlGroup">小组</param>
        /// <param name="someDate">某天日期,查询范围的逻辑为改天的周一至周日。</param>
        /// <returns></returns>
        public ActionResult Index(string ddlGroup, DateTime? someDate)
        {
            ViewBag.Message = "A slim online task scheduling application!";

            //获取默认分组当前周的任务
            ddlGroup = ddlGroup ?? AppSetting.Instance.GetString("DefaultGroupID");
            ViewBag.GroupID = ddlGroup;

            //<summary>
            // 获取所有分组
            // </summary>
            // <returns>Data_Groups</returns>
            var groups = unitOfWork.TheGroupRepo.GetAll();
            ViewBag.Data_Groups = new SelectList(groups, "Id", "Name", ddlGroup);

            // <summary>
            // 获取用户列表
            // </summary>
            // <returns>Data_Users</returns>
            var userservice = new User(unitOfWork);
            var users = userservice.GetAll();
            ViewBag.Data_Users = users;
            //获取Task 任务
            //使用XML文件
            Task taskService = new Task(unitOfWork);

            //解析查询的开始时间和结束时间
            someDate = someDate ?? DateHelper.CurMonday;
            var sdate = DateHelper.GetMonday(someDate.Value);
            var edate = sdate.AddDays(6);
            ViewBag.StartDate = sdate;
            ViewBag.CurMonday = DateHelper.CurMonday;

            //从tapd拿数据
            try
            {
                taskService.GetTapdTasks(ddlGroup, sdate, edate);
            }catch(Exception ex)
            {

            }
            //获取任务数据
            var tasks = taskService.GetAll(ddlGroup, sdate, edate);

            //测试
            var demoBiz = new DemoData(unitOfWork);
            tasks = tasks.Count == 0 ? demoBiz.GetAll(ddlGroup, sdate, edate) : tasks;

            var Data_Task_User = new Dictionary<string, Dictionary<string, List<Task>>>();
            //循环每个人
            foreach (var user in users)
            {
                string userid = user.Id;
                Dictionary<string, List<Task>> uTasks = new Dictionary<string, List<Task>>();
                List<Task> task1 = new List<Task>(),
                    task2 = new List<Task>(),
                    task3 = new List<Task>(),
                    task4 = new List<Task>(),
                    task5 = new List<Task>(),
                    task6 = new List<Task>(),
                    task7 = new List<Task>();
                //循环该人下面的任务
                foreach (var task in tasks)
                {
                    //用户id不匹配
                    if (userid!=task.UserId)
                    {
                        continue;
                    }
                    //日期不匹配
                    if ( (task.CreatedAt < sdate) || (task.CreatedAt > edate) )
                    {
                        continue;
                    }

                    //周一
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Monday)
                    {
                        task1.Add(task);

                    }
                    //周二
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Thursday)
                    {
                        task2.Add(task);
                    }
                    //周三
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Wednesday)
                    {
                        task3.Add(task);
                    }
                    //周四
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Tuesday)
                    {
                        task4.Add(task);
                    }
                    //周五
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Friday)
                    {
                        task5.Add(task);
                    }
                    //周六
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Saturday)
                    {
                        task6.Add(task);
                    }
                    //周日
                    if (task.CreatedAt.DayOfWeek == DayOfWeek.Sunday)
                    {
                        task7.Add(task);
                    }

                }//for

                uTasks.Add(sdate.ToString("yyyy-MM-dd"),task1);
                uTasks.Add(sdate.AddDays(1).ToString("yyyy-MM-dd"), task2);
                uTasks.Add(sdate.AddDays(2).ToString("yyyy-MM-dd"), task3);
                uTasks.Add(sdate.AddDays(3).ToString("yyyy-MM-dd"), task4);
                uTasks.Add(sdate.AddDays(4).ToString("yyyy-MM-dd"), task5);
                uTasks.Add(sdate.AddDays(5).ToString("yyyy-MM-dd"), task6);
                uTasks.Add(sdate.AddDays(6).ToString("yyyy-MM-dd"), task7);

                Data_Task_User.Add(userid,uTasks);

            }

            return View(Data_Task_User);
        }