Beispiel #1
0
        public JsonResult DeleteNextStepRun(int idStep)
        {
            HttpStatusCode status = HttpStatusCode.OK;
            string         message;
            object         response;
            StepRun        runstep     = stepService.findsteprun(idStep);
            List <StepRun> liststeprun = stepService.findStepsOfRunProcess(runstep.idProcess);
            StepRun        stepback    = new StepRun();

            foreach (StepRun item in liststeprun)
            {
                if (item.Id != runstep.Id)
                {
                    stepback = item;
                }
            }

            if (stepback.Figure == "Diamond")
            {
                StepRun stepbacknotdiamond = liststeprun.Where(x => x.NextStep1 == stepback.Key).OrderByDescending(x => x.Created_At).FirstOrDefault();
                stepService.removeStepRun(stepback);
                stepService.deletenextsteprun(runstep, stepbacknotdiamond);
            }
            else
            {
                stepService.deletenextsteprun(runstep, stepback);
            }
            message  = "Created ProcessRun Successfully";
            response = new { message = message, status = status };
            SetFlash(FlashType.success, "Delete Step");
            return(Json(response, JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public ActionResult Detail(int processid)
        {
            string  idUser     = User.Identity.GetUserId();
            Process processrun = processService.findProcess(processid, true);

            if (processrun == null)
            {
                return(HttpNotFound());
            }

            List <Role>    listrole             = roleService.findListRoleOfProcess(processid);
            Group          group                = groupService.findGroup(processrun.IdGroup);
            List <RoleRun> listroleruns         = roleService.findlistrolerun(listrole);
            List <Step>    listStep             = stepService.findStepsOfProcess(processid);
            ProcessRun     runprocess           = processService.findProcessRunByProcessId(processrun.Id);
            ProcessRun     ktra                 = db.ProcessRuns.Where(x => x.IdProcess == processrun.Id).FirstOrDefault();
            List <StepRun> liststepofrunprocess = new List <StepRun>();

            if (runprocess != null)
            {
                liststepofrunprocess = stepService.findStepsOfRunProcess(runprocess.Id);
            }


            List <Step> listnextstep1 = new List <Step>();
            List <Step> listnextstep2 = new List <Step>();
            Step        start         = listStep.Where(x => x.StartStep == true).FirstOrDefault();

            if (start != null)
            {
                listnextstep1.Add(start);
            }
            int z = 0;
            int t = 0;

            for (int j = 0; j < listStep.Count; j++)
            {
                if (j < listnextstep1.Count())
                {
                    if (listnextstep1[j].NextStep1 == 0)
                    {
                        break;
                    }
                    do
                    {
                        if (z == listStep.Count)
                        {
                            z = 0;
                        }
                        if (listStep[z].Key == listnextstep1[j].NextStep2 && listStep[z].StartStep == false)
                        {
                            listnextstep2.Add(listStep[z]);
                            if (listnextstep1[j].Figure == "Diamond")
                            {
                            }
                            else
                            {
                                z = 0;
                                break;
                            }
                        }
                        if (listStep[z].Key == listnextstep1[j].NextStep1 && listStep[z].StartStep == false)
                        {
                            listnextstep1.Add(listStep[z]);
                            if (listnextstep1[j].Figure == "Diamond")
                            {
                            }
                            else
                            {
                                z = 0;
                                break;
                            }
                        }
                        z++;
                    } while (z < listStep.Count);
                }
            }
            if (listnextstep2.Count() > 0)
            {
                for (int j = 0; j < listStep.Count; j++)
                {
                    if (j < listnextstep2.Count())
                    {
                        if (listnextstep2[j].NextStep1 == 0)
                        {
                            break;
                        }
                        do
                        {
                            if (listStep[t].Key == listnextstep2[j].NextStep1 && listStep[t].StartStep == false)
                            {
                                listnextstep2.Add(listStep[t]);
                                t = 0;
                                break;
                            }
                            t++;
                        } while (t < listStep.Count);
                    }
                }
            }
            List <Step> liststepgiong = new List <Step>();

            for (int i = 0; i < listnextstep1.Count; i++)
            {
                for (int j = 0; j < listnextstep2.Count; j++)
                {
                    if (listnextstep1[i].Key == listnextstep2[j].Key)
                    {
                        liststepgiong.Add(listnextstep2[j]);
                    }
                }
            }

            for (int i = 0; i < listnextstep2.Count; i++)
            {
                if (liststepgiong.Count != 0 && listnextstep2.Count != 0)
                {
                    for (int j = 0; j < liststepgiong.Count; j++)
                    {
                        if (listnextstep2[i].Key == liststepgiong[j].Key)
                        {
                            listnextstep2.Remove(listnextstep2[i]);
                        }
                    }
                }
            }
            //hàm xóa các phần tử giống nhau trong mảng
            //cho list 1
            IEnumerable <Step> gionglist1 = listnextstep1.Distinct();

            listnextstep1 = gionglist1.ToList();
            // cho list 2
            IEnumerable <Step> gionglist2 = listnextstep2.Distinct();

            listnextstep2 = gionglist2.ToList();

            foreach (Step item in listnextstep2)
            {
                listnextstep1.Add(item);
            }
            StepRun runnextstep = new StepRun();

            foreach (StepRun steprun in liststepofrunprocess.Where(x => x.Status1.Name == "Running"))
            {
                runnextstep = steprun;
            }

            //get processrun file
            string             processRunPath = string.Format("Upload/{0}/{1}", group.Id, processrun.Id);
            List <FileManager> files          = fileService.findFiles(group.Id, processRunPath);

            ViewData["ListRole"]     = listrole;
            ViewData["ProcessRun"]   = processrun;
            ViewData["ListRoleRuns"] = listroleruns;
            ViewBag.ListRunStep      = liststepofrunprocess.Where(x => x.Figure == "Step");
            ViewBag.Checkprocessrun  = ktra;
            ViewData["StepisNext"]   = runnextstep;
            ViewData["UserRoles"]    = participateService.getRoleOfMember(idUser, group.Id);
            //file
            ViewData["Files"] = files;
            return(View(listnextstep1));
        }
        public ActionResult MyTask(int groupid)
        {
            string         idUser      = User.Identity.GetUserId();
            List <Process> listprocess = processService.findListProcess(groupid);
            //if (listprocess.Count == 0) return HttpNotFound();
            //tìm role user trong group
            Participate userrole = participateService.getRoleOfMember(idUser, groupid);

            //tìm tất cả các role nào user đc phân trong processrun
            List <RoleRun> listrolerun = roleService.findlistrolerunbyiduser(idUser);
            List <Role>    listrole    = new List <Role>();

            foreach (var rolerun in listrolerun)
            {
                Role role = roleService.findrolebyidrolerun(rolerun);
                listrole.Add(role);
            }

            //tìm tất cả các task user đc gán trong từng process
            // sau đó kiểm trả các task nào user đc gán bằng roleid trong list task trên
            // => tìm ra đc các task user đc gán có trong từng process
            List <ProcessRun> listprocessrun  = new List <ProcessRun>();
            List <object>     jListProcessRun = new List <object>();

            foreach (var process in listprocess)
            {
                ProcessRun processrun = processService.findProcessRunByProcessId(process.Id);
                if (processrun != null)
                {
                    listprocessrun.Add(processrun);
                }
            }

            foreach (var processrun in listprocessrun)
            {
                List <StepRun> liststeprun = stepService.findStepsOfRunProcess(processrun.Id);
                //tạo Jprocessrun
                List <object> jlisttaskrunopen = new List <object>();
                List <object> jlisttaskrundone = new List <object>();
                //List<object> jlisttaskrunfinish = new List<object>();
                foreach (var steprun in liststeprun)
                {
                    List <TaskProcessRun> listtaskrun = taskService.findruntaskofstep(steprun.Id);
                    if (listtaskrun.Any())
                    {
                        foreach (var taskrun in listtaskrun)
                        {
                            object jTaskRun = new
                            {
                                id          = taskrun.Id,
                                name        = taskrun.Name,
                                description = taskrun.Description,
                                rolename    = taskrun.IdRole == null ? "Manager" : taskrun.Role.Name,
                                status      = taskrun.Status1.Name,
                                valueform   = taskrun.ValueFormJson
                            };
                            if (userrole.IsManager)
                            {
                                if (taskrun.Status1.Name == "Open")
                                {
                                    jlisttaskrunopen.Add(jTaskRun);
                                }
                                if (taskrun.Status1.Name == "Done")
                                {
                                    jlisttaskrundone.Add(jTaskRun);
                                }
                                //if (taskrun.Status1.Name == "Finish")
                                //{
                                //    jlisttaskrunfinish.Add(jTaskRun);
                                //}
                            }
                            else
                            {
                                foreach (var role in listrole)
                                {
                                    if (taskrun.IdRole == role.Id)
                                    {
                                        if (taskrun.Status1.Name == "Open")
                                        {
                                            jlisttaskrunopen.Add(jTaskRun);
                                        }
                                        if (taskrun.Status1.Name == "Done")
                                        {
                                            jlisttaskrundone.Add(jTaskRun);
                                        }
                                        //if (taskrun.Status1.Name == "Finish")
                                        //{
                                        //    jlisttaskrunfinish.Add(jTaskRun);
                                        //}
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                object jprocessrun = new
                {
                    id     = processrun.IdProcess,
                    name   = processrun.Name,
                    status = processrun.Status1.Name,
                    task   = new
                    {
                        open = jlisttaskrunopen,
                        done = jlisttaskrundone,
                        //finish = jlisttaskrunfinish
                    }
                };
                jListProcessRun.Add(jprocessrun);
            }
            //khúc này nó sẽ return cái html về client
            //nên mình phải gán data vào view
            //var listprocesses = JArray.FromObject(jListProcessRun);
            ViewData["ListProcessRun"] = JArray.FromObject(jListProcessRun);
            return(View());
        }