using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.SupervisionManage; using EMIS.ViewModel; using System.Linq.Expressions; using EMIS.Entities; using Bowin.Common.Linq; using EMIS.DataLogic.SupervisionManage; using EMIS.CommonLogic.SystemServices; namespace EMIS.CommonLogic.SupervisionManage { public class SupDocumentServices : BaseServices, ISupDocumentServices, IFileUploadServices { public SupDocumentDAL supDocumentDAL { get; set; } public IGridResultSet GetSupDocumentViewGrid(ConfiguretView conditionView, int? documentType, Guid? collegeID, int? pageIndex, int? pageSize) { Expression> userExp = (x => true); Expression> supdocumentExp = (x => true); if (collegeID.HasValue) { userExp = userExp.And(x => x.CF_Staff.CollegeID == collegeID); } if (documentType.HasValue) { supdocumentExp = supdocumentExp.And(x => x.DocumentType == documentType); } var query = supDocumentDAL.GetSupDocumentView(supdocumentExp); if (!string.IsNullOrEmpty(conditionView.ConditionValue)) { query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue); } query = query.OrderBy(x => x.DocumentTypeID).ThenBy(x => x.Title); return query.ToGridResultSet(pageIndex, pageSize); } public SupDocumentView GetSupDocumentView(Guid? documentID) { return supDocumentDAL.GetSupDocumentView(x => x.DocumentID == documentID).FirstOrDefault(); } public List GetFileList(Guid? formID) { return supDocumentDAL.GetDocumentAttachmentQueryable(x => x.DocumentID == formID).ToList(); } public void Save(SupDocumentView supDocumentView, List fileList) { try { if (fileList.Count > 1) { throw new Exception("单条记录只能上传一个文件"); } if (fileList.Count() <= 0) { throw new Exception("必须上传文件"); } var supDocument = new SUP_SupDocument(); var dbSupDocument = supDocumentDAL.supDocumentRepository.GetSingle(x => x.DocumentID == supDocumentView.DocumentID); if (dbSupDocument != null) { supDocument = this.supDocumentDAL.supDocumentRepository .GetSingle(x => x.DocumentID == supDocumentView.DocumentID, (x => x.SUP_DocumentAttachment)); UnitOfWork.Remove(x => x.DocumentID == supDocument.DocumentID); if (supDocument == null) { throw new Exception("当前编辑的记录可能已被其他人删除。"); } SetModifyStatus(supDocument); } else { var checksupDocument = this.supDocumentDAL.supDocumentRepository.GetSingle(x => x.Title == supDocumentView.Title); if (checksupDocument != null) { throw new Exception("已存在相同标题的督导文件记录。"); } supDocument.DocumentID = Guid.NewGuid(); this.SetNewStatus(supDocument); UnitOfWork.Add(supDocument); } supDocument.Title = supDocumentView.Title; supDocument.DocumentType = supDocumentView.DocumentTypeID; supDocument.SUP_DocumentAttachment = new HashSet(); fileList.ToList().ForEach(x => { var attachment = new SUP_DocumentAttachment(); attachment.DocumeAttachmentID = Guid.NewGuid(); attachment.DocumentID = supDocument.DocumentID; attachment.Name = x.FileName; attachment.Url = x.FileUrl; this.SetNewStatus(attachment); UnitOfWork.Add(attachment); }); UnitOfWork.Commit(); } catch (Exception) { throw; } } public void Delete(IList documentIDList) { UnitOfWork.Delete(x => documentIDList.Contains(x.DocumentID)); UnitOfWork.Delete(x => documentIDList.Contains(x.DocumentID)); } public FileUploadView GetFileUploadViewByDocumentID(Guid? documentID) { FileUploadView fileUploadView = new FileUploadView(); var fileUploadViewList = supDocumentDAL.documentAttachmentRepository.GetList(x => x.DocumentID == documentID); if (fileUploadViewList != null) { fileUploadView.FileID = fileUploadViewList.FirstOrDefault().DocumeAttachmentID; fileUploadView.FileName = fileUploadViewList.FirstOrDefault().Name; fileUploadView.FileUrl = fileUploadViewList.FirstOrDefault().Url; fileUploadView.FormID = fileUploadViewList.FirstOrDefault().DocumentID; } return fileUploadView; } } }