Esempio n. 1
0
        public void DeleteAttachedFile(ItemFileLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("ItemFileLink", "can not be null");
            }
            var oldFileId = link.File.ItemId;

            _environment.Execute(ItemFileLinksQueries.GetDeleteQuery(link.ParentId, link.ParentTypeId, link.File.ItemId));

            if (oldFileId > 0)
            {
                DeleteFileIfFileHasNoLinks(oldFileId);
            }
        }
Esempio n. 2
0
        public int SaveAttachedFile(ItemFileLink link)
        {
            if (link == null)
            {
                throw new ArgumentNullException("ItemFileLink", "can not be null");
            }

            var dsAfterInsertLink = new DataSet();
            var existsFileId      = FindFileId(link.File);

            if (existsFileId > 0)
            {
                //Присваиваем fileId  файла, обновляем линк и возвращаем Id файла
                link.File.ItemId = existsFileId;

                dsAfterInsertLink = _environment.Execute(ItemFileLinksQueries.GetMergeQuery(), ItemFileLinksQueries.GetParameters(link));
                link.ItemId       = DbTypes.ToInt32(dsAfterInsertLink.Tables[0].Rows[0][0]);

                return(existsFileId);
            }
            //Запоминаем fileId старого файла
            var oldFileId = link.File.ItemId;

            var ds = _environment.Execute(AttachedFileQueries.GetInsertQuery(), AttachedFileQueries.GetParameters(link.File));
            //Запоминаем fileId нового файла
            var newFileId = DbTypes.ToInt32(ds.Tables[0].Rows[0][0]);

            link.File.ItemId = newFileId;

            dsAfterInsertLink = _environment.Execute(ItemFileLinksQueries.GetMergeQuery(), ItemFileLinksQueries.GetParameters(link));
            link.ItemId       = DbTypes.ToInt32(dsAfterInsertLink.Tables[0].Rows[0][0]);

            if (oldFileId > 0)
            {
                DeleteFileIfFileHasNoLinks(oldFileId);
            }

            return(newFileId);
        }