Пример #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
        /// <summary>
        /// Update diagram tasks
        /// </summary>
        /// <param name="action">DiagramRequestModel object</param>
        /// <param wfs="diagramData">WorkFlowService object</param>
        private void UpdateTasks(DiagramRequestModel action, WorkFlowService wfs)
        {
            TaskWFM task = null;

            switch (action.Action)
            {
                case DiagramAction.Inserted:
                    // add new diagram task entity
                    if (action.UpdatedTask.GUID == Guid.Empty)
                    {
                        action.UpdatedTask.GUID = Guid.NewGuid();
                    }
                    task = DataMapperView.DoMapping<TaskViewModel, TaskWFM>(action.UpdatedTask);
                    wfs.SaveTask(task, false);
                    break;
                case DiagramAction.Deleted:
                    // remove diagram tasks
                    wfs.RemoveTask((int)action.SourceId, false);
                    break;
                case DiagramAction.Updated:
                    // update diagram task
                    task = DataMapperView.DoMapping<TaskViewModel, TaskWFM>(action.UpdatedTask);
                    wfs.SaveTask(task, false);
                    break;
                default:
                    action.Action = DiagramAction.Error;
                    break;
            }
        }
Пример #3
0
        /// <summary>
        /// Update diagram links
        /// </summary>
        /// <param name="action">DiagramRequestModel object</param>
        /// <param name="wfs">WorkFlowService object</param>
        private void UpdateLinks(DiagramRequestModel action, WorkFlowService wfs)
        {
            LinkWFM link = null;

            switch (action.Action)
            {
                case DiagramAction.Inserted:
                    // add new diagram link
                    if (action.UpdatedLink.GUID == Guid.Empty)
                    {
                        action.UpdatedLink.GUID = Guid.NewGuid();
                    }
                    link = DataMapperView.DoMapping<LinkViewModel, LinkWFM>(action.UpdatedLink);
                    wfs.SaveLink(link, false);
                    break;
                case DiagramAction.Deleted:
                    // remove diagram link
                    wfs.RemoveLink((int)action.SourceId, false);
                    break;
                case DiagramAction.Updated:
                    // update diagram link
                    link = DataMapperView.DoMapping<LinkViewModel, LinkWFM>(action.UpdatedLink);
                    wfs.SaveLink(link, false);
                    break;
                default:
                    action.Action = DiagramAction.Error;
                    break;
            }
        }
Пример #4
0
        /// <summary>
        /// Record updates came from diagram
        /// </summary>
        /// <param name="wfs">WorkFlowService object</param>
        public void MakeUpdate(WorkFlowService wfs)
        {
            try
            {
                if (actions.Count>0)
                {
                    foreach (var action in actions)
                    {
                        switch (action.Mode)
                        {
                            case DiagramMode.Tasks:
                                UpdateTasks(action, wfs);
                                break;
                            case DiagramMode.Links:
                                UpdateLinks(action, wfs);
                                break;
                        }
                    }

                    wfs.SaveAllChanges();

                    foreach (var action in actions)
                    {
                        if (action.Action == DiagramAction.Inserted)
                        {
                            switch (action.Mode)
                            {
                                case DiagramMode.Tasks:
                                    if (action.UpdatedTask.TaskId == 0)
                                    {
                                        action.UpdatedTask.TaskId = wfs.GetTaskIDByGUID(action.UpdatedTask.GUID);
                                    }
                                    break;
                                case DiagramMode.Links:
                                    if (action.UpdatedLink.LinkId == 0)
                                    {
                                        action.UpdatedLink.LinkId = wfs.GetLinkIDByGUID(action.UpdatedLink.GUID);
                                    }
                                    break;
                            }
                        }
                    }
                }
            }
            catch
            {
                // return error to client if something went wrong
                actions.ForEach(g => { g.Action = DiagramAction.Error; });
            }
        }
Пример #5
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");
        }
Пример #6
0
        /// <summary>
        /// Displays tasks report 
        /// </summary>
        /// <returns>HTML response</returns>
        public ActionResult TasksReport()
        {
            IList<string> roles = new List<string>();
            EmployeeViewModel employee = null;
            List<TaskWFM> gottenTasks = null;
            List<TaskViewModel> tasks = new List<TaskViewModel>();

            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);
                    }
                }
                if (gottenTasks!=null && gottenTasks.Count > 0)
                {
                    tasks = new ViewModelConverter().CreateTaskTypedRange(gottenTasks);
                }
                ViewBag.ProjectList = wfs.GetTasksProjects();
                ViewBag.HolderList = wfs.GetTasksHolders();
            }
            if (Request.IsAjaxRequest())
            {
                string holder = HttpContext.Request.Form["Holder"];
                string project = HttpContext.Request.Form["Project"];
                List<TaskViewModel> filteredtasks = tasks.
                    Where(t => (t.Holder == (String.IsNullOrEmpty(holder) ? t.Holder : holder)
                        && t.ProjectName == (String.IsNullOrEmpty(project) ? t.ProjectName : project)))
                        .ToList();
                return PartialView("TasksReportPartial", filteredtasks);
            }
            return View(tasks);
        }