示例#1
0
        /// <summary>
        /// Displays available tasks/links
        /// </summary>
        /// <returns>Json response</returns>
        public ActionResult Diagram()
        {
            DiagramAdapter DAdapter = new DiagramAdapter();
            JsonResult json = new JsonResult();
            IList<string> roles = new List<string>();
            EmployeeViewModel employee = null;
            IEnumerable<TaskWFM> gottenTasks = null;

            using (WorkFlowService wfs = new WorkFlowService("WorkFlowDbConnection"))
            {
                using (UserManager<ApplicationUser> userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())))
                {
                    ApplicationUser user = userManager.FindByName(User.Identity.Name);
                    if (user != null)
                    {
                        roles = userManager.GetRoles(user.Id);
                        EmployeeWFM employeeWMF = wfs.GetEmployeeByIdentityID(user.Id);
                        employee = DataMapperView.DoMapping<EmployeeWFM, EmployeeViewModel>(employeeWMF);
                    }
                }
                if (roles.Contains("admin") || roles.Contains("manager") || employee != null)
                {
                    if (roles.Contains("admin") || roles.Contains("manager"))
                    {
                        gottenTasks = wfs.GetAllTasks();
                    }
                    else
                    {
                        gottenTasks = wfs.GetEmployeeTasks(employee.HolderCode);
                    }
                    List<TaskViewModel> viewTasks = new ViewModelConverter().CreateTaskRange(gottenTasks);

                    IEnumerable<LinkWFM> gottenLinks = wfs.GetAllLinks();
                    List<LinkViewModel> viewLinks = new ViewModelConverter().CreateLinkRange(gottenLinks);

                    json = DAdapter.CreateJson(viewTasks, viewLinks);
                }
                else
                {
                    return View(json);
                }
            }
            return View(json);
        }
示例#2
0
        public ContentResult SaveDiagramChanges(FormCollection form)
        {
            DiagramAdapter DAdapter = new DiagramAdapter();
            DAdapter.ParseJson(form, Request.QueryString["gantt_mode"]);

            using (WorkFlowService wfs = new WorkFlowService("WorkFlowDbConnection"))
            {
                DAdapter.MakeUpdate(wfs);
            }

            return Content(DAdapter.ResposeToDiagram().ToString(), "text/xml");
        }