예제 #1
0
        public void AddFileReference(Part part, CaseDO caseDO)
        {
            if (caseDO == null)
            {
                return;
            }

            if (caseDO.IsAdded)
            {
                var oldFile = this.unitOfWork.DbContext.Set<GvaLotFile>()
                    .SingleOrDefault(f => f.LotPartId == part.PartId);
                if (oldFile != null)
                {
                    this.DeleteLotFile(oldFile);
                }

                var newFile = this.AddLotFile(part, caseDO);
            }
            else
            {
                var lotFileId = caseDO.LotFileId;
                var lotFile = this.unitOfWork.DbContext.Set<GvaLotFile>()
                        .Include(f => f.DocFile)
                        .SingleOrDefault(f => f.GvaLotFileId == lotFileId);

                this.unitOfWork.DbContext.Set<GvaAppLotFile>()
                    .Where(ga => ga.GvaLotFileId == lotFileId)
                    .Load();

                this.unitOfWork.DbContext.Set<GvaFile>()
                    .Include(f => f.GvaLotFiles)
                    .Where(f => f.GvaFileId == lotFile.GvaFileId)
                    .Load();

                if (caseDO.IsDeleted)
                {
                    this.DeleteLotFile(lotFile);
                }
                else
                {
                    this.UpdateLotFile(lotFile, caseDO);
                }
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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;
        }