コード例 #1
0
        public JsonResult AddMember(TaskMember taskMember, string member, int TaskId)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = 400;

                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                return(Json(errorList, JsonRequestBehavior.AllowGet));
            }
            taskMember.TaskId = TaskId;

            string[] emails = member.Split(' ');
            foreach (var email in emails)
            {
                string e   = email.Split(',', '\t', ';')[0];
                var    usr = db.Users.FirstOrDefault(u => u.Email == e);
                if (usr != null)
                {
                    taskMember.UserId = usr.Id;
                }
                db.TaskMembers.Add(taskMember);
                db.SaveChanges();
            }
            taskMember.Task = db.Tasks.Find(taskMember.TaskId);
            taskMember.User = db.Users.Find(taskMember.UserId);
            return(Json(new
            {
                User = taskMember.User.Name + " " + taskMember.User.Surname,
                taskMember.User.Photo,
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public bool DeleteDelegate(int idTask)
        {
            TaskMember TM = _db.TaskMembers.Where(x => x.idTask == idTask).FirstOrDefault();

            _db.TaskMembers.Remove(TM);
            _db.SaveChanges();
            return(true);
        }
コード例 #3
0
        // run checklist
        public void addPostListTask(List <TaskItemViewModel> taskItem, int checklistId)
        {
            foreach (var item in taskItem)
            {
                List <ContentDetail> contentDetails = new List <ContentDetail>();
                List <TaskMember>    taskMembers    = new List <TaskMember>();
                TaskItem             task           = new TaskItem();
                task.ChecklistId = checklistId;
                task.DueTime     = DateTime.Parse(item.DueTime);
                task.Name        = item.Name;
                task.Priority    = item.Priority;
                //  task.TaskStatus = item.TaskStatus;
                task.TaskStatus = "Running";
                context.TaskItem.Add(task);
                context.SaveChanges();
                var getTask = context.TaskItem.Where(t => t.Name.Equals(item.Name) && t.DueTime.Equals(task.DueTime) && t.TaskStatus.Equals("Running") && t.ChecklistId == checklistId).FirstOrDefault();
                int order   = 1;
                foreach (var content in item.ContentDetails)
                {
                    if (content.Id != 0)
                    {
                        ContentDetail detail = new ContentDetail();
                        detail.ImageSrc     = content.ImageSrc;
                        detail.Label        = content.Label;
                        detail.OrderContent = order;
                        detail.TaskItemId   = getTask.Id;
                        detail.Text         = content.Text;
                        detail.Type         = content.Type;
                        contentDetails.Add(detail);
                    }
                    order = order + 1;
                }
                foreach (var user in item.UserId)
                {
                    TaskMember member = new TaskMember();
                    member.UserId = user.Id;
                    member.TaskId = getTask.Id;
                    taskMembers.Add(member);
                }
                context.ContentDetail.AddRange(contentDetails);
                context.TaskMember.AddRange(taskMembers);
                context.SaveChanges();

                //context.Task
            }
        }
コード例 #4
0
        //add list task of template
        public void addListTaskItem(List <TaskItemViewModel> taskItem, int checklistId)
        {
            foreach (var item in taskItem)
            {
                List <ContentDetail> contentDetails = new List <ContentDetail>();
                List <TaskMember>    taskMembers    = new List <TaskMember>();
                TaskItem             task           = new TaskItem();
                task.ChecklistId = checklistId;
                task.DueTime     = DateTime.ParseExact(item.DueTime, "dd/MM/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                task.Name        = item.Name;
                task.Priority    = item.Priority;
                //task.TaskStatus = item.TaskStatus;
                task.TaskStatus = "Template";
                context.TaskItem.Add(task);
                context.SaveChanges();
                var getTask = context.TaskItem.Where(t => t.Name.Equals(item.Name) && t.DueTime.Equals(task.DueTime) && t.TaskStatus.Equals("Template")).FirstOrDefault();
                var i       = 1;
                foreach (var content in item.ContentDetails)
                {
                    if (content.Id != 0)
                    {
                        ContentDetail detail = new ContentDetail();
                        detail.ImageSrc     = content.ImageSrc;
                        detail.Label        = content.Label;
                        detail.OrderContent = i;
                        detail.TaskItemId   = getTask.Id;
                        detail.Text         = content.Text;
                        detail.Type         = content.Type;
                        contentDetails.Add(detail);
                    }
                    i++;
                }
                foreach (var user in item.UserId)
                {
                    TaskMember member = new TaskMember();
                    member.UserId = user.Id;
                    member.TaskId = getTask.Id;
                    taskMembers.Add(member);
                }
                context.ContentDetail.AddRange(contentDetails);
                context.TaskMember.AddRange(taskMembers);
                context.SaveChanges();

                //context.Task
            }
        }
コード例 #5
0
        public async Task <IActionResult> Edit(string projectId, string taskId)
        {
            int tId = _task.UnprotectTaskId(taskId);

            var task = await _task.GetTaskAsync(tId);

            TaskCreateViewModel taskVM = new TaskCreateViewModel();

            taskVM.ProjectId    = projectId;
            taskVM.Task         = task;
            taskVM.TaskStatuses = await _taskStatus.GetAllTaskStatusAsync();

            (await _projectMember.GetAllMembersForProjectAsync(task.ProjectId))
            .ForEach(pm => taskVM.MembersPartOfProject.Add(pm.Member));

            taskVM.MembersAvailableToAdd = (await _member.GetAllMembersAsync())
                                           .Where(m => m.Id != task.MemberId)
                                           .ToList();

            List <TaskMember> taskMembers = await _taskMember.GetAllMembersForTaskAsync(tId);

            taskMembers.ForEach(tm => taskVM.MembersAvailableToRemove.Add(tm.Member));

            foreach (Member memberAvailableToAdd in taskVM.MembersAvailableToAdd.ToList())
            {
                Member projectMember = taskVM.MembersPartOfProject.FirstOrDefault(pm => pm.Id == memberAvailableToAdd.Id);
                if (projectMember != null)
                {
                    taskVM.MembersAvailableToAdd.Remove(memberAvailableToAdd);
                    continue;
                }

                TaskMember taskMember = taskMembers.FirstOrDefault(tm => tm.MemberId == memberAvailableToAdd.Id);
                if (taskMember != null)
                {
                    taskVM.MembersAvailableToAdd.Remove(memberAvailableToAdd);
                    taskMembers.Remove(taskMember);
                }
            }

            taskVM.MembersAvailableToAdd    = taskVM.MembersAvailableToAdd.OrderBy(m => m.GetFullName).ToList();
            taskVM.MembersAvailableToRemove = taskVM.MembersAvailableToRemove.OrderBy(m => m.GetFullName).ToList();

            return(View(taskVM));
        }
コード例 #6
0
        public static TaskEntity GetTaskDetail(string taskID)
        {
            TaskEntity model = null;
            DataSet    ds    = TaskDAL.BaseProvider.GetTaskDetail(taskID);

            DataTable taskTB = ds.Tables["OrderTask"];

            if (taskTB.Rows.Count > 0)
            {
                model = new TaskEntity();
                model.FillData(taskTB.Rows[0]);
                model.Owner = OrganizationBusiness.GetUserCacheByUserID(model.OwnerID, model.ClientID);

                //成员
                DataTable memberTB = ds.Tables["TaskMember"];
                model.TaskMembers = new List <IntFactoryEntity.Task.TaskMember>();
                if (memberTB.Rows.Count > 0)
                {
                    foreach (DataRow m in memberTB.Rows)
                    {
                        TaskMember member = new TaskMember();
                        member.FillData(m);
                        member.Member = OrganizationBusiness.GetUserCacheByUserID(member.MemberID, model.ClientID);
                        model.TaskMembers.Add(member);
                    }
                }

                //订单基本信息
                model.Order = new OrderEntity();
                model.Order.FillData(ds.Tables["Order"].Rows[0]);
                if (!string.IsNullOrEmpty(model.Order.BigCategoryID))
                {
                    var category = SystemBusiness.BaseBusiness.GetProcessCategoryByID(model.Order.BigCategoryID);
                    model.Order.ProcessCategoryName = category == null ? "" : category.Name;
                }
                if (!string.IsNullOrEmpty(model.Order.CategoryID))
                {
                    var category  = ProductsBusiness.BaseBusiness.GetCategoryByID(model.Order.CategoryID);
                    var pcategory = ProductsBusiness.BaseBusiness.GetCategoryByID(category.PID);
                    model.Order.CategoryName = pcategory.CategoryName + " > " + category.CategoryName;
                }
            }

            return(model);
        }
コード例 #7
0
        public JsonResult TaskCreate(Task task,
                                     TaskMember taskMember,
                                     HttpPostedFileBase fileBase,
                                     string member)
        {
            if (!ModelState.IsValid)
            {
                Response.StatusCode = 400;

                var errorList = ModelState.Values.SelectMany(m => m.Errors)
                                .Select(e => e.ErrorMessage)
                                .ToList();

                return(Json(errorList, JsonRequestBehavior.AllowGet));
            }
            if (fileBase == null)
            {
                ModelState.AddModelError("file", "Please select file");
            }
            string date     = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            string filename = date + fileBase.FileName;
            string path     = Path.Combine(Server.MapPath("~/Uploads"), filename);

            Models.File startfile = new Models.File();
            startfile.UserId = Convert.ToInt32(Session["UserId"]);
            fileBase.SaveAs(path);
            startfile.Name   = filename;
            startfile.Weight = fileBase.ContentLength.ToString() + "-mb";
            startfile.Type   = fileBase.ContentType;

            task.UserId = Convert.ToInt32(Session["UserId"]);
            if (db.Tasks.FirstOrDefault(t => t.Slug == task.Slug) != null)
            {
                task.Slug = task.Slug + DateTime.Now.ToString("yyyyMMddHHmmssfff");
            }
            db.Tasks.Add(task);
            db.SaveChanges();

            startfile.TaskId = task.Id;
            db.Files.Add(startfile);
            db.SaveChanges();

            TaskMember taskMem = new TaskMember()
            {
                UserId = task.UserId,
                TaskId = task.Id
            };

            db.TaskMembers.Add(taskMem);
            db.SaveChanges();

            string[] emails = member.Split(' ');
            foreach (var email in emails)
            {
                string e = email.Split(',', '\t', ';')[0];
                taskMember.TaskId = task.Id;
                var usr = db.Users.FirstOrDefault(u => u.Email == e);
                if (usr != null)
                {
                    taskMember.UserId = usr.Id;
                }
                db.TaskMembers.Add(taskMember);
                db.SaveChanges();
            }
            Activity act = new Activity()
            {
                UserId = task.UserId,
                Desc   = "create task " + task.Name,
                Date   = DateTime.Now
            };

            db.Activities.Add(act);
            db.SaveChanges();
            return(Json(new
            {
                task.Id,
                task.Slug,
                task.UserId
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #8
0
ファイル: TaskController.cs プロジェクト: Michauxquan/MTest
        public ActionResult Detail(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(Redirect("/Task/MyTask"));
            }

            TaskModel taskModel = new Models.TaskModel();
            //任务详情
            var task = TaskBusiness.GetTaskDetail(id);

            if (task == null)
            {
                Response.Write("<script>alert('任务不存在');location.href='/Task/MyTask';</script>");
                Response.End();
            }
            taskModel.Task = task;

            //任务对应的订单详情
            var order = task.Order;
            ProcessCategoryEntity      item           = SystemBusiness.BaseBusiness.GetProcessCategoryByID(order.BigCategoryID);
            List <CategoryItemsEntity> categoryItems  = new List <CategoryItemsEntity>();
            List <CategoryItemsEntity> categoryItems2 = new List <CategoryItemsEntity>();

            if (item.CategoryItems != null)
            {
                categoryItems  = item.CategoryItems.FindAll(m => m.Type == 4).ToList();
                categoryItems2 = item.CategoryItems.FindAll(m => m.Type == 3);
            }
            ViewBag.plateMarkItems = categoryItems;
            ViewBag.Modules        = categoryItems2;
            if (task.Mark == 11)
            {
                order.Details = OrdersBusiness.BaseBusiness.GetOrderDetailsByOrderID(task.OrderID);
                if (order.Details == null)
                {
                    order.Details = new List <IntFactoryEntity.OrderDetail>();
                }
                if (order.OrderType == 1)
                {
                    order.OrderAttrs = OrdersBusiness.BaseBusiness.GetOrderArrrsByOrderID(task.OrderID);
                }
            }
            taskModel.Order = order;

            //判断查看权限
            if (!IsSeeRoot(task, order))
            {
                Response.Write("<script>alert('您无查看任务权限');location.href='/Task/MyTask';</script>");
                Response.End();
            }

            //任务剩余时间警告
            var isWarn = false;

            if (task.FinishStatus == 1)
            {
                if (task.EndTime > DateTime.Now)
                {
                    var totalHour   = (task.EndTime - task.AcceptTime).TotalHours;
                    var residueHour = (task.EndTime - DateTime.Now).TotalHours;

                    var residue = residueHour / totalHour;
                    if (residue < 0.333)
                    {
                        isWarn = true;
                    }
                }
            }
            taskModel.IsWarn = isWarn;

            //当前用户是否为任务负责人
            taskModel.IsTaskOwner = task.OwnerID.Equals(CurrentUser.UserID, StringComparison.OrdinalIgnoreCase) ? true : false;

            //当前用户是否有编辑权限
            var        isEditTask = false;
            TaskMember member     = task.TaskMembers.Find(a => a.MemberID.ToLower() == CurrentUser.UserID.ToLower());

            if (member != null)
            {
                if (member.PermissionType == 2)
                {
                    isEditTask = true;
                }
            }
            taskModel.IsEditTask = isEditTask;

            //订单的品类属性
            taskModel.ProductAttr = new IntFactoryEntity.ProductAttr();
            //制版任务
            if (task.Mark == 12 || task.Mark == 22)
            {
                taskModel.ProductAttr = new ProductsBusiness().GetTaskPlateAttrByCategoryID(order.CategoryID);
            }

            //任务完成周期
            if (task.FinishStatus == 2)
            {
                taskModel.FinishDay = (int)Math.Ceiling((task.CompleteTime - task.AcceptTime).TotalDays);
            }
            //操作权限
            taskModel.IsRoot  = (task.Status != 8 && (task.FinishStatus == 1 || task.LockStatus == 2) && (taskModel.IsEditTask || taskModel.IsTaskOwner));
            ViewBag.TaskModel = taskModel;

            return(View());
        }