public CaseDO(GvaLotFile lotFile) { this.LotFileId = lotFile.GvaLotFileId; if (lotFile.DocFile != null) { this.File = new FileDataDO(lotFile.DocFile); } else if (lotFile.GvaFile != null) { this.File = new FileDataDO(lotFile.GvaFile); } this.BookPageNumber = lotFile.PageIndex; this.PageCount = lotFile.PageNumber; this.Note = lotFile.Note; this.CaseType = new NomValue() { NomValueId = lotFile.GvaCaseTypeId, Name = lotFile.GvaCaseType.Name, Alias = lotFile.GvaCaseType.Alias }; this.IsDocFile = lotFile.DocFileId.HasValue; this.Applications = lotFile.GvaAppLotFiles .Where(af => af.GvaApplication != null) .Select(af => new ApplicationNomDO(af.GvaApplication)) .ToList(); }
public IHttpActionResult PostCreatePartAndLink(int id, string setPartAlias, int docId, PartDO<JObject> linkNewPart) { using (var transaction = this.unitOfWork.BeginTransaction()) { GvaApplication application = this.applicationRepository.Find(id); Lot lot = this.lotRepository.GetLotIndex(application.LotId); SetPart setPart = this.unitOfWork.DbContext.Set<SetPart>().FirstOrDefault(e => e.Alias == setPartAlias); string path = setPart.PathRegex.Remove(setPart.PathRegex.IndexOf("\\"), 4).Remove(0, 1) + "*"; PartVersion<JObject> partVersion = lot.CreatePart(path, linkNewPart.Part, this.userContext); lot.Commit(this.userContext, lotEventDispatcher); DocFile docFile; if (linkNewPart.Case.DocFileId.HasValue) { docFile = this.unitOfWork.DbContext.Set<DocFile>().FirstOrDefault(e => e.DocFileId == linkNewPart.Case.DocFileId); } else { var doc = this.docRepository.Find(docId); var docFileTypes = this.unitOfWork.DbContext.Set<DocFileType>().ToList(); var docFileType = docFileTypes.FirstOrDefault(e => e.Extention == Path.GetExtension(linkNewPart.Case.File.Name)); if (docFileType == null) { docFileType = docFileTypes.FirstOrDefault(e => e.Alias == "UnknownBinary"); } docFile = doc.CreateDocFile( linkNewPart.Case.DocFileKind.NomValueId, docFileType.DocFileTypeId, null, linkNewPart.Case.Name, linkNewPart.Case.File.Name, String.Empty, linkNewPart.Case.File.Key, true, true, this.userContext); } GvaLotFile lotFile = new GvaLotFile() { LotPart = partVersion.Part, DocFile = docFile, GvaCaseTypeId = linkNewPart.Case.CaseType.NomValueId, PageIndex = linkNewPart.Case.BookPageNumber, PageIndexInt = this.fileRepository.GetPageIndexInt(linkNewPart.Case.BookPageNumber), PageNumber = linkNewPart.Case.PageCount }; GvaAppLotFile gvaAppLotFile = new GvaAppLotFile() { GvaApplication = application, GvaLotFile = lotFile, DocFile = docFile }; this.applicationRepository.AddGvaLotFile(lotFile); this.applicationRepository.AddGvaAppLotFile(gvaAppLotFile); this.unitOfWork.Save(); this.lotRepository.ExecSpSetLotPartTokens(partVersion.PartId); transaction.Commit(); return Ok(); } }
private void DeleteLotFile(GvaLotFile lotFile) { foreach (var gvaAppLotFile in lotFile.GvaAppLotFiles.ToList()) { this.unitOfWork.DbContext.Set<GvaAppLotFile>().Remove(gvaAppLotFile); } if (lotFile.GvaFile != null) { this.unitOfWork.DbContext.Set<GvaFile>().Remove(lotFile.GvaFile); } if (lotFile.DocFile != null) { this.unitOfWork.DbContext.Set<DocFile>().Remove(lotFile.DocFile); } this.unitOfWork.DbContext.Set<GvaLotFile>().Remove(lotFile); }
private void UpdateLotFile(GvaLotFile lotFile, CaseDO caseDO) { lotFile.GvaCaseTypeId = caseDO.CaseType.NomValueId; lotFile.PageIndex = caseDO.BookPageNumber; lotFile.PageIndexInt = GetPageIndexInt(caseDO.BookPageNumber); lotFile.PageNumber = caseDO.PageCount; lotFile.Note = caseDO.Note; if (caseDO.File != null) { if (!lotFile.GvaFileId.HasValue) { GvaFile file = new GvaFile() { Filename = caseDO.File.Name, MimeType = caseDO.File.MimeType, FileContentId = caseDO.File.Key }; this.unitOfWork.DbContext.Set<GvaFile>().Add(file); lotFile.GvaFile = file; } else if (lotFile.GvaFile.FileContentId != caseDO.File.Key) { lotFile.GvaFile.Filename = caseDO.File.Name; lotFile.GvaFile.MimeType = caseDO.File.MimeType; lotFile.GvaFile.FileContentId = caseDO.File.Key; } } else if (lotFile.GvaFileId.HasValue) { this.unitOfWork.DbContext.Set<GvaFile>().Remove(lotFile.GvaFile); } var nonModifiedApps = lotFile.GvaAppLotFiles.Join( caseDO.Applications, gf => gf.GvaApplicationId, a => a.ApplicationId, (gf, a) => gf); var removedApplications = lotFile.GvaAppLotFiles.Except(nonModifiedApps).ToList(); foreach (var application in removedApplications) { this.unitOfWork.DbContext.Set<GvaAppLotFile>().Remove(application); } foreach (var application in caseDO.Applications) { var appLotFile = lotFile.GvaAppLotFiles.SingleOrDefault(af => af.GvaApplicationId == (int)application.ApplicationId); if (appLotFile == null) { appLotFile = new GvaAppLotFile() { GvaApplicationId = application.ApplicationId, GvaLotFile = lotFile }; this.unitOfWork.DbContext.Set<GvaAppLotFile>().Add(appLotFile); } } }
private GvaLotFile AddLotFile(Part part, CaseDO caseDO) { GvaFile file = null; if (caseDO.File != null) { file = new GvaFile() { Filename = caseDO.File.Name, MimeType = caseDO.File.MimeType, FileContentId = caseDO.File.Key }; this.unitOfWork.DbContext.Set<GvaFile>().Add(file); } GvaLotFile newLotFile = new GvaLotFile() { LotPart = part, GvaFile = file, GvaCaseTypeId = caseDO.CaseType.NomValueId, PageIndex = (string)caseDO.BookPageNumber, PageIndexInt = GetPageIndexInt(caseDO.BookPageNumber), PageNumber = (int?)caseDO.PageCount, Note = caseDO.Note, }; this.unitOfWork.DbContext.Set<GvaLotFile>().Add(newLotFile); foreach (var application in caseDO.Applications) { GvaAppLotFile appLotFile = new GvaAppLotFile() { GvaApplicationId = application.ApplicationId, GvaLotFile = newLotFile }; this.unitOfWork.DbContext.Set<GvaAppLotFile>().Add(appLotFile); } return newLotFile; }