123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- 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<SupDocumentView> GetSupDocumentViewGrid(ConfiguretView conditionView, int? documentType, Guid? collegeID, int? pageIndex, int? pageSize)
- {
- Expression<Func<Sys_User, bool>> userExp = (x => true);
- Expression<Func<SUP_SupDocument, bool>> 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<FileUploadView> GetFileList(Guid? formID)
- {
- return supDocumentDAL.GetDocumentAttachmentQueryable(x => x.DocumentID == formID).ToList();
- }
- public void Save(SupDocumentView supDocumentView, List<FileUploadView> 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<SUP_DocumentAttachment>(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<SUP_DocumentAttachment>();
- 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<Guid?> documentIDList)
- {
- UnitOfWork.Delete<SUP_DocumentAttachment>(x => documentIDList.Contains(x.DocumentID));
- UnitOfWork.Delete<SUP_SupDocument>(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;
- }
- }
- }
|