Пример #1
0
        protected void ProcessAttacherForSave(FileAttacher attacher, IEnumerable<HttpPostedFileBase> uploadedFiles)
        {
            if (attacher == null)
            {
                return;
            }

            if (attacher.ExtantFiles != null)
            {
                var delFiles = attacher.ExtantFiles.Where(item => !String.IsNullOrEmpty(item.Deleted)).ToList();

                if (delFiles.Count() > 0)
                {
                    if (attacher.DeleteFiles == null)
                    {
                        attacher.DeleteFiles = new List<DeleteFileInfo>();
                    }
                    foreach (var f in delFiles)
                    {
                        attacher.DeleteFiles.Add(new DeleteFileInfo { ID = f.ID });
                    }
                    attacher.ExtantFiles.RemoveAll(item => !String.IsNullOrEmpty(item.Deleted));
                }
            }

            if (attacher.CachedFiles != null)
            {
                attacher.CachedFiles.RemoveAll(item => !String.IsNullOrEmpty(item.Deleted));

                foreach (var cacheFile in attacher.CachedFiles)
                {
                    var data = TempData[cacheFile.CacheID];
                    Byte[] fileData = data as Byte[];
                    cacheFile.FileData = fileData;
                }
            }

            if ((attacher.NewFiles != null) && (uploadedFiles != null))
            {
                var upldFileList = uploadedFiles.ToList();
                int cnt = Math.Min(attacher.NewFiles.Count(), upldFileList.Count());
                if (cnt > 0)
                {
                    if (attacher.CachedFiles == null)
                    {
                        attacher.CachedFiles = new List<CachedFileInfo>();
                    }
                    for (int i = 0; i < cnt; i++)
                    {
                        var upldFile = upldFileList[i];
                        if ((upldFile != null) && (upldFile.ContentLength > 0))
                        {
                            attacher.CachedFiles.Add(
                                new CachedFileInfo(Guid.NewGuid().ToString("n"), upldFile, attacher.NewFiles[i])
                            );
                        }
                    }
                }
            }

            attacher.NewFiles = null;
        }
Пример #2
0
        protected void UpdateJobAttachments(ProductionJob editJob, FileAttacher attacher)
        {
            if (attacher != null)
            {
                List<string> delIDS = attacher.DelFileIDs();
                if (delIDS.IsAny())
                {
                    string sql = "DELETE FROM FG_PRDN_JOB_ATTACHMENT WHERE FG_PRDN_JOB_ATT_ID IN (" +
                        PrdnDataHelper.ParmFormatList(delIDS.Count()) + ")";
                    PrdnDBContext.ExecuteStoreCommand(sql, delIDS.Cast<object>().ToArray());
                }

                if (attacher.NotNullAny(a => a.ExtantFiles))
                {
                    foreach (var dbFile in attacher.ExtantFiles)
                    {
                        var mods = editJob.Attachments.Where(a =>
                            (a.ID == dbFile.DecimalID)
                            && ((a.AttachmentTypeID != dbFile.AttTypeID) && (dbFile.AttTypeID != null)
                                || a.Description != dbFile.Description)
                        );
                        foreach (var modFile in mods)
                        {
                            modFile.AttachmentTypeID = (decimal)dbFile.AttTypeID;
                            modFile.Description = dbFile.Description;
                        }
                    }
                };
                if (attacher.NotNullAny(a => a.CachedFiles))
                {
                    foreach (var newFile in attacher.CachedFiles)
                    {
                        CST.Prdn.Data.ProductionJobAttachment newAttachment = new CST.Prdn.Data.ProductionJobAttachment
                        {   //JobID = editJob.ID,
                            FileName = newFile.FileName,
                            MimeType = newFile.MimeType,
                            Description = newFile.Description,
                            Attachment = newFile.FileData
                        };
                        if (newFile.AttTypeID != null)
                        {
                            newAttachment.AttachmentTypeID = (decimal)newFile.AttTypeID;
                        }
                        editJob.Attachments.Add(newAttachment);
                    }
                }
            }
        }
Пример #3
0
        protected void ProcessAttacherForPost(FileAttacher attacher)
        {
            if (attacher == null)
            {
                return;
            }

            attacher.AttTypesFunc = GetAttTypes;

            if (attacher.CachedFiles != null)
            {
                foreach (var cacheFile in attacher.CachedFiles)
                {
                    TempData[cacheFile.CacheID] = cacheFile.FileData;
                }
            }

            // clear attacher model state info so Post view render does not display old list info
            foreach (var delPair in ModelState.Where(p => (p.Key.Contains("Attacher"))).ToList())
            {
                ModelState.Remove(delPair.Key);
            }
        }