public List <EventItemFile> AttachmentsAddFiles(CommunityEventItem eventItem, List <dtoModuleUploadedItem> items, Boolean visibleForItem)
        {
            List <EventItemFile> attachments = null;
            Boolean isInTransaction          = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                litePerson person = Manager.GetLitePerson(UC.CurrentUserID);
                if (items.Any() && eventItem != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    attachments = new List <EventItemFile>();
                    DateTime date = DateTime.Now;
                    foreach (dtoModuleUploadedItem item in items)
                    {
                        EventItemFile attachment = new EventItemFile();
                        attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                        attachment.IdCommunity  = eventItem.IdCommunityOwner;
                        attachment.IdEventOwner = (eventItem.EventOwner != null ? eventItem.EventOwner.Id : 0);
                        attachment.IdItemOwner  = eventItem.Id;
                        attachment.Item         = item.ItemAdded;
                        attachment.isVisible    = visibleForItem;
                        attachment.Owner        = person;
                        Manager.SaveOrUpdate(attachment);
                        liteModuleLink link = new liteModuleLink(item.Link.Description, item.Link.Permission, item.Link.Action);
                        link.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                        link.DestinationItem = (ModuleObject)item.Link.ModuleObject;
                        link.AutoEvaluable   = false;
                        link.SourceItem      = ModuleObject.CreateLongObject(attachment.Id, attachment, (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile, attachment.IdCommunity, ModuleCommunityDiary.UniqueID, ServiceModuleID());
                        Manager.SaveOrUpdate(link);
                        attachment.Link = link;

                        if (item.ItemAdded.IsInternal)
                        {
                            if (item.ItemAdded.Module == null)
                            {
                                item.ItemAdded.Module = new lm.Comol.Core.FileRepository.Domain.ItemModuleSettings();
                            }
                            item.ItemAdded.Module.IdObject     = attachment.Id;
                            item.ItemAdded.Module.IdObjectType = (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile;
                            Manager.SaveOrUpdate(item.ItemAdded);
                        }

                        Manager.SaveOrUpdate(attachment);
                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <EventItemFile> AttachmentsLinkFiles(long idEvent, long idEventItem, List <ModuleActionLink> links, Boolean visibleForItem, Boolean?visibleForRepository)
        {
            List <EventItemFile> attachments = null;
            Boolean isInTransaction          = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                CommunityEventItem item   = EventItemGet(idEventItem);
                litePerson         person = Manager.GetLitePerson(UC.CurrentUserID);
                Boolean            updateRepositoryItems = false;
                if (links.Any() && item != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    DateTime date = DateTime.Now;
                    attachments = new List <EventItemFile>();
                    foreach (ModuleActionLink link in links)
                    {
                        EventItemFile attachment = QueryAttachments(a => a.Deleted == BaseStatusDeleted.None && a.IdItemOwner == idEventItem).ToList().Where(a => a.Item == (liteRepositoryItem)link.ModuleObject.ObjectOwner).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (attachment == null)
                        {
                            attachment = new EventItemFile();
                            attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Owner        = person;
                            attachment.IdCommunity  = item.IdCommunityOwner;
                            attachment.IdEventOwner = (item.EventOwner != null ? item.EventOwner.Id : 0);
                            attachment.IdItemOwner  = item.Id;
                            attachment.Item         = (liteRepositoryItem)link.ModuleObject.ObjectOwner;
                            attachment.isVisible    = visibleForItem;
                            attachment.Version      = null;
                            Manager.SaveOrUpdate(attachment);
                            if (!attachment.Item.IsInternal && visibleForRepository.HasValue && visibleForRepository.Value != attachment.Item.IsVisible)
                            {
                                attachment.Item.IsVisible = visibleForRepository.Value;
                                Manager.SaveOrUpdate(attachment.Item);
                                updateRepositoryItems = true;
                            }

                            liteModuleLink mLink = new liteModuleLink(link.Description, link.Permission, link.Action);
                            mLink.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            mLink.DestinationItem = (ModuleObject)link.ModuleObject;
                            mLink.AutoEvaluable   = false;
                            mLink.SourceItem      = ModuleObject.CreateLongObject(attachment.Id, attachment, (int)ModuleCommunityDiary.ObjectType.DiaryItemLinkedFile, attachment.IdCommunity, ModuleCommunityDiary.UniqueID, ServiceModuleID());
                            Manager.SaveOrUpdate(mLink);
                            attachment.Link = mLink;
                            Manager.SaveOrUpdate(attachment);
                        }
                        else if (attachment.Deleted != BaseStatusDeleted.None)
                        {
                            attachment.RecoverMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            if (attachment.Item != null && attachment.Item.IsInternal && attachment.Item.Deleted != BaseStatusDeleted.None)
                            {
                                attachment.Item.Deleted = BaseStatusDeleted.None;
                                attachment.Item.UpdateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                                Manager.SaveOrUpdate(attachment.Item);
                            }
                            Manager.SaveOrUpdate(attachment);
                        }
                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
                if (updateRepositoryItems && attachments.Any(a => !a.Item.IsInternal))
                {
                    RepositoryIdentifier identifier = attachments.Where(a => !a.Item.IsInternal).Select(a => a.Item.Repository).FirstOrDefault();
                    foreach (EventItemFile attachment in attachments.Where(a => !a.Item.IsInternal))
                    {
                        Manager.Refresh(Manager.Get <lm.Comol.Core.FileRepository.Domain.RepositoryItem>(attachment.Item.Id));
                    }
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.Repository(identifier));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersViewOfRepository(identifier));
                    lm.Comol.Core.DomainModel.Helpers.CacheHelper.PurgeCacheItems(lm.Comol.Core.FileRepository.Domain.CacheKeys.UsersSizeViewOfRepository(identifier));
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }