コード例 #1
0
ファイル: CommentController.cs プロジェクト: Zilmill/huajian
        protected CommentListModel PrepareCommentListModel(FileVersion modelVersion)
        {
            CommentListModel result = new CommentListModel();
            var modelFile           = modelVersion.EngineeringFile;

            result.ModelId = modelFile.Id;

            result.ProjectName      = modelFile.Engineering.Project.ProjectName;
            result.CommentCount     = modelFile.Comments.Count();
            result.EngineeringName  = modelFile.Engineering.Name;
            result.ModelStatus      = modelVersion.Status;
            result.StatusUpdateTime = modelVersion.UpdateStateTime.ToString("yyyy-MM-dd HH:mm:ss");
            result.OrganizationType = CurrentCustomer.Organization.OrganizationType;

            result.AvaliableProfessions.Add(new SelectListItem()
            {
                Text = "全部", Value = "0", Selected = true
            });
            modelVersion.ModelProfessions.ToList().ForEach(e =>
            {
                result.AvaliableProfessions.Add(new SelectListItem()
                {
                    Text  = DictionaryService.CommentProfessionDictionary.Find(n => n.Id == e.ProfessionId).DisplayName,
                    Value = e.ProfessionId.ToString()
                });
            });

            result.AvaliableStatus.Add(new SelectListItem()
            {
                Text = "全部", Value = "", Selected = true
            });
            WorkFlow.GetAllCommentStatus().ForEach(e => result.AvaliableStatus.Add(new SelectListItem()
            {
                Text  = e,
                Value = e,
            }));

            result.AvaliableCommentType = EnumHelper.EnumToSelectListItem <CommentType>();

            var lastesModelVersion = modelFile.FileVersions.Where(e => e.FileType == FileType.Model).OrderByDescending(e => e.UpLoadeTime).FirstOrDefault();

            if (lastesModelVersion == null)
            {
                throw new ArgumentException(nameof(lastesModelVersion));
            }

            modelFile.FileVersions.Where(e => e.FileType == FileType.Model).OrderByDescending(e => e.UpLoadeTime).ToList().ForEach(e =>
            {
                if (e.Id == modelVersion.Id)
                {
                    result.SelectedVersionId = e.Id;
                }

                result.AvaliableVersions.Add(new SelectListItem()
                {
                    Text     = string.Format("模型版本{0}", e.VersionNo),
                    Value    = e.Id.ToString(),
                    Selected = e.Id == modelVersion.Id,
                });
            });

            result.AvaliableVersions.Find(e => e.Value == lastesModelVersion.Id.ToString()).Text = "当前版本";

            return(result);
        }