Exemple #1
0
        public ApplicationLotFileDO(GvaAppLotFile appFile, DocFile docFile)
            : this()
        {
            this.HasAppFile = appFile == null ? false : true;

            if (appFile != null)
            {
                this.GvaLotFileId = appFile.GvaLotFileId;
                this.PartIndex = appFile.GvaLotFile.LotPart.Index;
                this.SetPartName = appFile.GvaLotFile.LotPart.SetPart.Name;
                this.SetPartAlias = appFile.GvaLotFile.LotPart.SetPart.Alias;
                this.PageNumber = appFile.GvaLotFile.PageNumber;
                this.PageIndex = appFile.GvaLotFile.PageIndex;

                if (appFile.GvaLotFile.GvaCaseType != null)
                {
                    this.GvaCaseTypeName = appFile.GvaLotFile.GvaCaseType.Name;
                }

                if (appFile.DocFile != null)
                {
                    this.DocFileId = appFile.DocFile.DocFileId;
                    this.DocFileKindId = appFile.DocFile.DocFileKindId;
                    this.DocFileTypeId = appFile.DocFile.DocFileTypeId;
                    this.DocId = appFile.DocFile.DocId;
                    this.Name = appFile.DocFile.Name;

                    this.File.Key = appFile.DocFile.DocFileContentId;
                    this.File.Name = appFile.DocFile.DocFileName;
                }
                else if (appFile.GvaLotFile.GvaFile != null)
                {
                    this.File.Key = appFile.GvaLotFile.GvaFile.FileContentId;
                    this.File.Name = appFile.GvaLotFile.GvaFile.Filename;
                }
                else if (appFile.GvaLotFile.DocFile != null)
                {
                    this.File.Key = appFile.GvaLotFile.DocFile.DocFileContentId;
                    this.File.Name = appFile.GvaLotFile.DocFile.DocFileName;
                }
            }
            else if (docFile != null)
            {
                this.DocFileId = docFile.DocFileId;
                this.DocFileKindId = docFile.DocFileKindId;
                this.DocFileTypeId = docFile.DocFileTypeId;
                this.DocId = docFile.DocId;
                this.Name = docFile.Name;

                this.File.Key = docFile.DocFileContentId;
                this.File.Name = docFile.DocFileName;
            }
        }
        public IHttpActionResult PostLinkPart(int id, int docFileId, int partId)
        {
            using (var transaction = this.unitOfWork.BeginTransaction())
            {
                GvaApplication application = this.applicationRepository.Find(id);
                DocFile docFile = this.unitOfWork.DbContext.Set<DocFile>().FirstOrDefault(e => e.DocFileId == docFileId);

                GvaLotFile gvaLotFile = this.unitOfWork.DbContext.Set<GvaLotFile>()
                    .Include(e => e.LotPart.SetPart)
                    .FirstOrDefault(e => e.LotPartId == partId);

                if (gvaLotFile != null)
                {
                    GvaAppLotFile gvaAppLotFile = this.unitOfWork.DbContext.Set<GvaAppLotFile>()
                        .Include(e => e.DocFile)
                        .FirstOrDefault(e => e.GvaApplicationId == id && e.GvaLotFileId == gvaLotFile.GvaLotFileId);

                    if (gvaAppLotFile == null)
                    {
                        GvaAppLotFile addGvaAppLotFile = new GvaAppLotFile()
                        {
                            GvaApplication = application,
                            GvaLotFile = gvaLotFile,
                            DocFile = docFile
                        };

                        this.applicationRepository.AddGvaAppLotFile(addGvaAppLotFile);
                    }
                    else if (gvaAppLotFile.DocFile == null)
                    {
                        gvaAppLotFile.DocFile = docFile;
                    }
                }

                this.unitOfWork.Save();

                transaction.Commit();

                return Ok();
            }
        }
Exemple #3
0
        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);
                }
            }
        }
        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();
            }
        }
Exemple #5
0
        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;
        }