public List <ProjectAttachment> AttachmentsAddFiles(Project project, PmActivity activity, List <dtoModuleUploadedItem> items)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (items.Any() && project != null && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    long dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                    attachments = new List <ProjectAttachment>();
                    DateTime date = DateTime.Now;
                    foreach (dtoModuleUploadedItem item in items)
                    {
                        ProjectAttachment attachment = new ProjectAttachment();
                        attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                        attachment.Activity     = activity;
                        attachment.Description  = "";
                        attachment.IsForProject = (activity == null);
                        attachment.Project      = project;
                        attachment.Type         = AttachmentType.file;
                        attachment.Item         = item.ItemAdded;
                        Manager.SaveOrUpdate(attachment);
                        ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                        Manager.SaveOrUpdate(aLink);
                        attachment.SharedItems.Add(aLink);
                        Manager.SaveOrUpdate(attachment);
                        ModuleLink link = new ModuleLink(item.Link.Description, item.Link.Permission, item.Link.Action);
                        link.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                        link.DestinationItem = (ModuleObject)item.Link.ModuleObject;
                        link.AutoEvaluable   = false;
                        if (attachment.IsForProject)
                        {
                            link.SourceItem = ModuleObject.CreateLongObject(project.Id, project, (int)ModuleProjectManagement.ObjectType.Project, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                        }
                        else
                        {
                            link.SourceItem = ModuleObject.CreateLongObject(activity.Id, activity, (int)ModuleProjectManagement.ObjectType.Task, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                        }
                        Manager.SaveOrUpdate(link);
                        attachment.Link = Manager.Get <liteModuleLink>(link.Id);
                        Manager.SaveOrUpdate(attachment);
                        attachments.Add(attachment);
                        if (activity == null)
                        {
                            project.Attachments.Add(attachment);
                        }
                        project.AttachmentLinks.Add(aLink);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <ProjectAttachment> AttachmentsLinkFiles(long idProject, long idActivity, List <ModuleActionLink> links)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                PmActivity activity = (idActivity > 0) ? Manager.Get <PmActivity>(idProject) : null;
                Project    project  = (idActivity == 0 && idProject > 0) ? Manager.Get <Project>(idProject) : ((activity == null) ? null : activity.Project);
                Person     person   = Manager.GetPerson(UC.CurrentUserID);
                if (links.Any() && project != null && (idActivity == 0 || activity != null) && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    DateTime date   = DateTime.Now;
                    long     dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                    attachments = new List <ProjectAttachment>();
                    foreach (ModuleActionLink link in links)
                    {
                        ProjectAttachment attachment = (from a in project.Attachments.Where(a => (idActivity == 0 && a.IsForProject) || (!a.IsForProject && a.Activity == activity))
                                                        select a).ToList().Where(a => a.Item == (liteRepositoryItem)link.ModuleObject.ObjectOwner).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (attachment == null)
                        {
                            attachment = new ProjectAttachment();
                            attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Activity     = activity;
                            attachment.Description  = "";
                            attachment.IsForProject = (activity == null);
                            attachment.Project      = project;
                            attachment.Type         = AttachmentType.file;
                            attachment.Item         = (liteRepositoryItem)link.ModuleObject.ObjectOwner;
                            attachment.Version      = null;

                            Manager.SaveOrUpdate(attachment);
                            ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                            Manager.SaveOrUpdate(aLink);
                            attachment.SharedItems.Add(aLink);
                            Manager.SaveOrUpdate(attachment);


                            ModuleLink mLink = new ModuleLink(link.Description, link.Permission, link.Action);
                            mLink.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            mLink.DestinationItem = (ModuleObject)link.ModuleObject;
                            mLink.AutoEvaluable   = false;
                            if (attachment.IsForProject)
                            {
                                mLink.SourceItem = ModuleObject.CreateLongObject(project.Id, project, (int)ModuleProjectManagement.ObjectType.Project, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                            }
                            else
                            {
                                mLink.SourceItem = ModuleObject.CreateLongObject(activity.Id, activity, (int)ModuleProjectManagement.ObjectType.Task, (project.Community != null) ? project.Community.Id : 0, ModuleProjectManagement.UniqueCode, GetIdModule());
                            }
                            Manager.SaveOrUpdate(mLink);
                            attachment.Link = Manager.Get <liteModuleLink>(mLink.Id);
                            Manager.SaveOrUpdate(attachment);
                            if (activity == null)
                            {
                                project.Attachments.Add(attachment);
                            }
                            project.AttachmentLinks.Add(aLink);
                        }
                        else if (attachment.Deleted != BaseStatusDeleted.None)
                        {
                            attachment.RecoverMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            foreach (ProjectAttachmentLink l in attachment.SharedItems.Where(s => s.Type == AttachmentLinkType.Owner))
                            {
                                l.DisplayOrder = dOrder++;
                                l.RecoverMetaInfo(person.Id, attachment.ModifiedIpAddress, attachment.ModifiedProxyIpAddress, attachment.ModifiedOn);
                            }
                        }

                        attachments.Add(attachment);
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
        public List <ProjectAttachment> AttachmentsAddUrl(long idProject, long idActivity, List <dtoUrl> urls)
        {
            List <ProjectAttachment> attachments = null;
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (urls != null && urls.Where(u => !String.IsNullOrEmpty(u.Address)).Any() && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    PmActivity activity = (idActivity > 0) ? Manager.Get <PmActivity>(idActivity) : null;
                    Project    project  = (idActivity == 0 && idProject > 0) ? Manager.Get <Project>(idProject) : ((activity == null) ? null : activity.Project);
                    if (project != null && (idActivity == 0 || activity != null))
                    {
                        long     dOrder = AttachmentsGetMaxDisplayOrder(project, activity);
                        DateTime date   = DateTime.Now;
                        attachments = new List <ProjectAttachment>();
                        foreach (dtoUrl item in urls.Where(u => !String.IsNullOrEmpty(u.Address) && Uri.IsWellFormedUriString(u.Address, UriKind.RelativeOrAbsolute)))
                        {
                            ProjectAttachment attachment = new ProjectAttachment();
                            attachment.CreateMetaInfo(person.Id, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Activity     = activity;
                            attachment.Description  = "";
                            attachment.IsForProject = (activity == null);
                            attachment.Project      = project;
                            attachment.Type         = AttachmentType.url;
                            attachment.Url          = item.Address;
                            attachment.UrlName      = item.Name;
                            Manager.SaveOrUpdate(attachment);

                            ProjectAttachmentLink aLink = GenerateLink(attachment, dOrder++);
                            Manager.SaveOrUpdate(aLink);
                            attachment.SharedItems.Add(aLink);
                            attachments.Add(attachment);
                            if (idActivity == 0)
                            {
                                project.Attachments.Add(attachment);
                            }
                            project.AttachmentLinks.Add(aLink);
                        }
                    }
                }
                if (!isInTransaction)
                {
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }