Ejemplo n.º 1
0
        public ActionResult Index(string shortCode)
        {
            if (string.IsNullOrEmpty(shortCode))
            {
                return(RedirectToAction("Index", "Schedule"));
            }

            var task    = m_dbAdapter.Task.GetTask(shortCode);
            var project = m_dbAdapter.Project.GetProjectById(task.ProjectId);

            task.ProjectName = project.Name;

            var taskViewModel = Toolkit.ConvertTask(task);

            GetPrevAndNextTaskShortCode(taskViewModel, task);
            taskViewModel.ProjectGuid = project.ProjectGuid;
            taskViewModel.TaskHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskViewModel.TaskHandler);

            taskViewModel.PrevTaskNameArray      = new List <string>();
            taskViewModel.PrevTaskShortCodeArray = new List <string>();
            foreach (var prevTaskId in task.PrevTaskIdArray)
            {
                var prevTask = m_dbAdapter.Task.GetTask(prevTaskId);
                taskViewModel.PrevTaskShortCodeArray.Add(prevTask.ShortCode);
                taskViewModel.PrevTaskNameArray.Add(prevTask.Description);
            }

            //Get task extension info.
            if (task.TaskExtensionId.HasValue)
            {
                var taskExtension = m_dbAdapter.Task.GetTaskExtension(task.TaskExtensionId.Value);
                taskExtension.TaskExtensionHandler = Platform.UserProfile.GetDisplayRealNameAndUserName(taskExtension.TaskExtensionHandler);
                taskViewModel.TaskExtension        = Toolkit.ConvertTaskExtension(taskExtension);

                var instance = TaskExFactory.CreateInstance(taskViewModel.TaskExtension.Type, shortCode, CurrentUserName);
                if (instance != null)
                {
                    //扩展工作页面初始化时的异常返回错误信息
                    object entity;
                    try
                    {
                        entity = instance.GetEntity();
                    }
                    catch (ApplicationException e)
                    {
                        entity = e.Message;
                    }
                    taskViewModel.TaskExtension.Info = entity;
                }
            }

            //Get task status history info.
            var taskStatusHitory = m_dbAdapter.Task.GetTaskStatusHistory(task.TaskId);

            if (taskStatusHitory != null)
            {
                var usernameCache = new Dictionary <string, string>();

                taskViewModel.TaskStatusHistory = new List <TaskStatusHistoryViewModel>();
                foreach (var item in taskStatusHitory)
                {
                    var viewModel = Toolkit.ConvertTaskStatusHistory(item);

                    string name = string.Empty;
                    if (usernameCache.ContainsKey(viewModel.TimeStampUserName))
                    {
                        name = usernameCache[viewModel.TimeStampUserName];
                    }
                    else
                    {
                        name = m_dbAdapter.Authority.GetNameByUserName(viewModel.TimeStampUserName);
                        usernameCache[viewModel.TimeStampUserName] = name;
                    }

                    name = string.IsNullOrEmpty(name) ? viewModel.TimeStampUserName
                        : (name + "(" + viewModel.TimeStampUserName + ")");
                    viewModel.TimeStampUserName = name;

                    taskViewModel.TaskStatusHistory.Add(viewModel);
                }
            }

            taskViewModel.ProjectSeriesStage = ProjectSeriesStage.存续期;
            if (project.ProjectSeriesId.HasValue && project.TypeId.HasValue && project.TypeId.Value == 1)
            {
                taskViewModel.ProjectSeriesStage = ProjectSeriesStage.发行;

                var projectSeries = m_dbAdapter.ProjectSeries.GetById(project.ProjectSeriesId.Value);
                taskViewModel.ProjectSeriesGuid = projectSeries.Guid;
            }

            return(View(taskViewModel));
        }