예제 #1
0
 public Boolean addTask(int UserId, Task t)
 {
     try
     {
         db.Set<User>().Find(UserId).Task.Add(t);
     }
     catch
     {
         return false;
     }
     return true;
 }
예제 #2
0
 public Boolean CommitTask(Task task, int UserId)
 {
     try
     {
         Activity ac = new Activity();
         ac.Operation = "提交";
         ac.Name = task.Name;
         ac.UserId = UserId;
         ac.CreateTime = DateTime.Now;
         ac.TaskId = task.Id;
         db.Set<Activity>().Add(ac);
         db.SaveChanges();
         return true;
     }
     catch
     {
         return false;
     }
 }
예제 #3
0
        public Boolean AddTask(Task task)
        {
            try
            {

                Activity ac = new Activity();
                ac.Operation = "Create";
                ac.Name = task.Name;
                ac.UserId = task.UserId;
                ac.CreateTime = DateTime.Now;
                db.Set<Task>().Add(task);
                db.Set<Activity>().Add(ac);
                db.SaveChanges();
                ac.TaskId = task.Id;
                db.SaveChanges();
                return true;
            }
            catch
            {
                return false;
            }
        }
예제 #4
0
 public ActionResult Create(FormCollection form)
 {
     User u = user.getUser((Session["User"] as LoginForm).Id);
     if (task.findTask(form["Name"]) != null)
     {
         return RedirectToAction("ErrorPage", "Error", new { Message = "事务名已存在" });
     }
     if (u.Role_Id <= 2)
     {
         Task t = new Task();
         t.Name = form["Name"];
         t.Status = 0;
         t.UserId = (Session["User"] as LoginForm).Id;
         if (!string.IsNullOrEmpty(form["Desc"]))
         {
             t.Desc = form["Desc"];
         }
         t.CreateTime = t.UpdateTime = System.DateTime.Now;
         foreach (var assign in form["Assign"].Replace(@"""", "").Split(',').ToList())
         {
             if (!user.addTask(Int32.Parse(assign), t))
             {
                 return RedirectToAction("ErrorPage", "Error", new { Message = "出错了,请与管理员联系" });
             }
         }
         try{
             string foldername =t.Name;
             string path = AppDomain.CurrentDomain.BaseDirectory + "/Files/";
             System.IO.Directory.CreateDirectory(path + foldername);
             task.save();
             Activity ac = new Activity();
             ac.CreateTime = DateTime.Now;
             ac.TaskId = t.Id;
             ac.Operation = "创建";
             ac.Name = t.Name;
             ac.UserId = u.Id;
             (new ActivityService()).AddActivity(ac);
             task.save();
         }
         catch
         {
             return RedirectToAction("ErrorPage", "Error", new { Message = "出错了,请与管理员联系" });
         }
         return RedirectToAction("Index", new { Id = 1 });
     }
     else
     {
         return RedirectToAction("ForbidPage", "Error");
     }
 }