public ActionResult TaskSchedule(int page = 1, string action = "", FormCollection collection = null, int id = 0) { conn.OpenConnection(); string sql_1 = "SELECT * FROM [Task] WHERE ID =" + id; DataTable dt = conn.Detail(sql_1); ViewBag.Data = dt; //string sql_id = "SELECT [User].UserName FROM [User] INNER JOIN [TaskSchedule] ON [User].ID = [TaskSchedule].PublisherID"; //DataTable dts = conn.Detail(sql_id); //string PublisherUserName = dts.Rows[0][0].ToString(); List <TaskSchedule> taskschedules = new List <TaskSchedule>(); string sql = "SELECT [TaskSchedule].*,[User].UserName FROM [TaskSchedule] INNER JOIN [Task] ON [Task].ID = [TaskSchedule].TaskID INNER JOIN [User] ON [TaskSchedule].PublisherID = [User].ID WHERE [TaskSchedule].TaskID = " + id + " ORDER BY [TaskSchedule].ID DESC "; DataSet ds = conn.Ds_List(sql); foreach (DataRow item in ds.Tables[0].Rows) { taskschedules.Add(new TaskSchedule { ID = int.Parse(item["ID"].ToString()), Content = item["Content"].ToString(), TaskID = int.Parse(item["TaskID"].ToString()), PublisherID = int.Parse(item["PublisherID"].ToString()), PublisherUserName = item["UserName"].ToString(), CreateTime = item["CreateTime"].ToString(), LastEditTime = item["LastEditTime"].ToString(), IsValid = bool.Parse(item["IsValid"].ToString()), }); } conn.CloseConnection(); TaskScheduleViewModel TaskScheduleViewModel = new TaskScheduleViewModel() { TaskSchedules = taskschedules.Skip((page - 1) * PageSize).Take(PageSize).ToList(), PagingInfo = new PagingInfo { CurrentPage = page, TotalItmes = taskschedules.Count, ItemsPerPage = PageSize } }; return(View(TaskScheduleViewModel)); }
public ICollection <TaskScheduleViewModel> GetTaskSchedule() { var models = new List <TaskScheduleViewModel>(); var list = _appDbContext.Tasks.Where(x => x.DueDate > DateTime.Now && x.Active) .Include(x => x.TaskRotation) .OrderBy(x => x.DueDate) .ToList(); foreach (var item in list) { var model = new TaskScheduleViewModel { Id = item.TaskId, DueDate = item.DueDate, TaskName = item.TaskName, TimeRemaining = GetTimeDifference(item.DueDate) }; models.Add(model); } return(models); }