示例#1
0
        public static List<TaskModel> GetByUser(string searchUser)
        {
            List<TaskModel> task_list = new List<TaskModel>();
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["tasks"].ConnectionString))
            {
                SqlCommand command = new SqlCommand("GetTasksByUser", connection);
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.Add("@user", SqlDbType.VarChar).Value = searchUser;

                connection.Open();
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        TaskModel task = new TaskModel();
                        task.Id = int.Parse(reader["id"].ToString());
                        task.DueDate = DateTime.Parse(reader["due_date"].ToString());
                        task.Priority = int.Parse(reader["priority"].ToString());
                        task.User = reader["user"].ToString();
                        task.Name = reader["name"].ToString();
                        task_list.Add(task);
                    }
                }
                connection.Dispose();
                return task_list;
            }
        }
示例#2
0
 public ActionResult Create(TaskModel task)
 {
     try
     {
         //TaskModel task = new TaskModel()
         //                         {
         //                             Name = collection["name"].ToString(),
         //                             DueDate = DateTime.Parse(collection["DueDate"].ToString()),
         //                             Priority = int.Parse(collection["priority.priority"].ToString()),
         //                             User = this.User.Identity.Name
         //                         };
         task.User = this.User.Identity.Name;
         if (ModelState.IsValid)
         {
             task.Save();
             return RedirectToAction("Index", "Home");
         }
         else
         {
             return View();
         }
     }
     catch
     {
         return View();
     }
 }