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; }
/// <summary> /// 从TAPD接口获取任务数据 /// </summary> /// <param name="gid">对应tapd接口的workspace_id或project_id</param> /// <param name="sTime"></param> /// <param name="eTime"></param> /// <returns></returns> public List<Task> GetTapdTasks(string gid,DateTime sTime,DateTime eTime) { var url = String.Format(AppSetting.Instance.GetString("URL_TAPD"),gid,sTime,eTime); XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(url); XmlNode root = xmldoc.DocumentElement; XmlNodeList xmllist = root.SelectNodes("Story"); List<Task> tasks_obj = new List<Task>(); foreach (XmlNode story in xmllist) { Task curr_task = new Task(); curr_task.Id = story.SelectNodes("id")[0].InnerText; curr_task.Name = story.SelectNodes("name")[0].InnerText; curr_task.Desc = "no ";// story.SelectNodes("description")[0].InnerText; curr_task.Creator = story.SelectNodes("creator")[0].InnerText; curr_task.CreatedAt = DateTime.Now; curr_task.GroupId = story.SelectNodes("workspace_id")[0].InnerText; curr_task.Level = story.SelectNodes("level")[0].InnerText; curr_task.Status = story.SelectNodes("status")[0].InnerText; curr_task.StartedAt = DateTime.Now; curr_task.Completed = DateTime.Now; curr_task.DoneAt = DateTime.Now; curr_task.ModifiedAt = DateTime.Now; curr_task.UserId = "hermanzhang";//TODO:看怎么搞到配置文件去 tasks_obj.Add(curr_task); } //保存至DB if (tasks_obj.Count>0) { SaveTaskList(tasks_obj); } return tasks_obj; }
/// <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); }
public JsonResult Update(TaskEditInfo vmodel) { var retVal = new Msg(); var taskService = new Task(unitOfWork); retVal = taskService.Update(vmodel); return Json(retVal); }