public Boolean SaveCertificationFile(CertificationType cType, Boolean withEmptyPlaceHolders, Int32 idCommunity, Int32 idUser, String cName, String cDescription, long idPath, long idSubActivity, Guid uniqueID, String extension, Boolean restore = false)
        {
            Certification cert = null;
            SubActivity   s    = Service.GetSubActivity(idSubActivity);

            if (s != null)
            {
                dtoCertification dto = dtoCertification.Create(cType);
                dto.Name = cName;
                if (!String.IsNullOrEmpty(cDescription) && cDescription.Contains("{0}"))
                {
                    cDescription = string.Format(cDescription, Service.GetPathName(idPath));
                }
                dto.Description           = cDescription;
                dto.IdCommunity           = idCommunity;
                dto.IdContainer           = idPath;
                dto.IdOwner               = idUser;
                dto.UniqueIdGeneratedFile = uniqueID;
                dto.FileExtension         = extension;
                dto.IdTemplate            = s.IdCertificate;
                dto.IdTemplateVersion     = s.IdCertificateVersion;
                dto.WithEmptyPlaceHolders = withEmptyPlaceHolders;
                dto.SourceItem            = ModuleObject.CreateLongObject(idSubActivity, s, (int)COL_BusinessLogic_v2.UCServices.Services_EduPath.ObjectType.SubActivity, idCommunity, COL_BusinessLogic_v2.UCServices.Services_EduPath.Codex, Service.ServiceModuleID());
                cert = ServiceCertifications.SaveUserCertification(dto);
            }

            return(cert != null);
        }
Exemplo n.º 2
0
        public void SaveTaskListFiles(Task task, int communityId, IList <ModuleActionLink> files, int moduleID, int objectTypeId, String moduleCode, Boolean AutoEvaluable)
        {
            try
            {
                Person person = Manager.GetPerson(UC.CurrentUserID);
                if (files.Count > 0)
                {
                    Manager.BeginTransaction();
                    Community community = Manager.GetCommunity(communityId);
                    foreach (ModuleActionLink file in files)
                    {
                        TaskListFile taskfile = (from f in Manager.GetAll <TaskListFile>(f => f.CommunityOwner == community && f.TaskOwner == task && f.ProjectOwner == task.Project && f.File == (BaseCommunityFile)file.ModuleObject.ObjectOwner) select f).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (taskfile == null)
                        {
                            taskfile = new TaskListFile();
                            taskfile.CommunityOwner = community;
                            taskfile.ProjectOwner   = task.Project;
                            taskfile.File           = (BaseCommunityFile)file.ModuleObject.ObjectOwner;
                            taskfile.TaskOwner      = task;
                            taskfile.Owner          = person;
                            taskfile.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress);
                        }
                        else
                        {
                            taskfile.UpdateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress);
                        }
                        taskfile.isVisible = true;

                        Manager.SaveOrUpdate(taskfile);

                        ModuleLink link = new ModuleLink(file.Description, file.Permission, file.Action);
                        link.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress);
                        link.DestinationItem = (ModuleObject)file.ModuleObject;
                        link.AutoEvaluable   = AutoEvaluable;
                        link.SourceItem      = ModuleObject.CreateLongObject(taskfile.Id, taskfile, objectTypeId, communityId, moduleCode, moduleID);
                        Manager.SaveOrUpdate(link);
                        taskfile.Link = link;
                        Manager.SaveOrUpdate(taskfile);
                        if (typeof(ModuleLongInternalFile) == file.ModuleObject.ObjectOwner.GetType())
                        {
                            ModuleLongInternalFile f = (ModuleLongInternalFile)file.ModuleObject.ObjectOwner;
                            f.ObjectOwner  = taskfile;
                            f.ObjectTypeID = objectTypeId;
                            Manager.SaveOrUpdate(f);
                        }

                        task.MetaInfo.ModifiedBy = taskfile.CreatedBy;
                        task.MetaInfo.ModifiedOn = taskfile.CreatedOn.Value;
                        Manager.SaveOrUpdate(task);
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                throw new lm.Comol.Core.Event.EventItemFileNotLinked(ex.Message, ex);
            }
        }
        private List <Certification> GetAvailableCertifications(dtoSubActivity item, Int32 idCommunity, Int32 idUser)
        {
            ModuleObject source = ModuleObject.CreateLongObject(item.Id, (int)COL_BusinessLogic_v2.UCServices.Services_EduPath.ObjectType.SubActivity, idCommunity, COL_BusinessLogic_v2.UCServices.Services_EduPath.Codex);

            source.ServiceID = Service.ServiceModuleID();
            source.FQN       = typeof(SubActivity).FullName;
            return(ServiceCertifications.GetUserCertifications(source, idUser, true));
        }
        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);
        }
        public void InitView()
        {
            int  IdCommunity       = UserContext.CurrentCommunityID;
            long idFile            = View.PreloadedFileId;
            BaseCommunityFile file = Service.GetItem(idFile);

            if (file != null && file.CommunityOwner != null)
            {
                IdCommunity = file.CommunityOwner.Id;
            }

            if (UserContext.isAnonymous)
            {
                View.SendToSessionExpiredPage(IdCommunity, UserContext.Language.Code);
            }
            else
            {
                View.BackUrl = View.PreloadedBackUrl;

                long moduleLinkId = View.PreloadedLinkId;
                View.ModuleLinkId = moduleLinkId;
                View.FileId       = idFile;
                if (idFile == 0 && moduleLinkId == 0)
                {
                    View.ShowUnkownFile(IdCommunity, ModuleID, CoreModuleRepository.UniqueID);
                }
                else
                {
                    Person     person = CurrentManager.GetPerson(UserContext.CurrentUserID);
                    ModuleLink link   = CurrentManager.Get <ModuleLink>(moduleLinkId);
                    ScormMetadataPermission permission = ScormMetadataPermission.none;
                    if (link == null && file == null)
                    {
                        View.ShowUnkownFile(IdCommunity, ModuleID, CoreModuleRepository.UniqueID);
                    }
                    else if (!file.isSCORM)
                    {
                        View.ShowNoScormFile(file.DisplayName);
                    }
                    else if ((link == null && file != null) || file.GetType() == typeof(CommunityFile))
                    {
                        IdCommunity = (file.CommunityOwner == null ? 0 : file.CommunityOwner.Id);
                        CoreModuleRepository module = Service.ServicePermission(UserContext.CurrentUserID, IdCommunity);
                        if (Service.HasPermissionToSeeRepositoryItem(idFile, module.Administration, module.Administration, UserContext.CurrentUserID))
                        {
                            permission = (module.Administration || (module.Edit && file.Owner == person)) ? ScormMetadataPermission.edit : ScormMetadataPermission.view;
                            View.InitializeMetadataControl(file.UniqueID, file.DisplayName, permission);
                        }
                        else
                        {
                            View.ShowNoPermissionToEditMetadata(IdCommunity, ModuleID, CoreModuleRepository.UniqueID, file.DisplayName);
                        }
                    }
                    else
                    {
                        IdCommunity = link.SourceItem.CommunityID;

                        ModuleObject linkedObject = ModuleObject.CreateLongObject(file.Id, file, (int)CoreModuleRepository.ObjectType.ScormPackage, IdCommunity, CoreModuleRepository.UniqueID);
                        permission = View.GetModuleLinkPermission(link.SourceItem.CommunityID, moduleLinkId, link.SourceItem, linkedObject, UserContext.CurrentUserID);
                        if (permission == ScormMetadataPermission.none)
                        {
                            View.ShowNoPermissionToEditMetadata(IdCommunity, link.SourceItem.ServiceID, link.SourceItem.ServiceCode, file.DisplayName);
                        }
                        else
                        {
                            View.InitializeMetadataControl(file.UniqueID, file.DisplayName, permission);
                        }
                    }
                }
            }
        }
        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> 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);
        }
        private ModuleGenericTemplateMessages GetPermissions(String moduleCode, long permissions, Int32 idCommunity, TemplateType type)
        {
            ModuleGenericTemplateMessages permission = null;
            Int32 idUser = UserContext.CurrentUserID;

            switch (type)
            {
            case TemplateType.Module:
                if (moduleCode == ModuleTemplateMessages.UniqueCode)
                {
                    permission = new ModuleGenericTemplateMessages(Service.GetPermission(idCommunity, OwnerType.Module));
                }
                else
                {
                    Int32 idModule = CurrentManager.GetModuleID(moduleCode);
                    dtoBaseTemplateOwner ownerInfo = View.PreloadOwnership;
                    ModuleObject         obj       = (ownerInfo.Type == OwnerType.Object) ? ModuleObject.CreateLongObject(ownerInfo.IdObject, ownerInfo.IdObjectType, ownerInfo.IdObjectCommunity, CurrentManager.GetModuleCode(ownerInfo.IdObjectModule), ownerInfo.IdObjectModule) : null;
                    if (obj != null && obj.ServiceID == 0 && !String.IsNullOrEmpty(obj.ServiceCode))
                    {
                        obj.ServiceID = CurrentManager.GetModuleID(obj.ServiceCode);
                    }
                    else if (obj != null && obj.ServiceID > 0 && String.IsNullOrEmpty(obj.ServiceCode))
                    {
                        obj.ServiceCode = CurrentManager.GetModuleCode(obj.ServiceID);
                    }
                    if (permissions > 0)
                    {
                        permission = View.GetModulePermissions(moduleCode, idModule, CurrentManager.GetModulePermission(UserContext.CurrentUserID, idCommunity, idModule), idCommunity, UserContext.UserTypeID, obj);
                    }
                    else
                    {
                        permission = View.GetModulePermissions(moduleCode, idModule, GetModulePermission(idCommunity, idModule), idCommunity, UserContext.UserTypeID, obj);
                    }
                }
                break;

            case TemplateType.User:
                Person  p         = GetCurrentUser(ref idUser);
                Boolean allowView = (p != null && p.TypeID != (Int32)UserTypeStandard.Guest && p.TypeID != (Int32)UserTypeStandard.PublicUser);

                permission                   = new ModuleGenericTemplateMessages("personal");
                permission.Add               = allowView;
                permission.Administration    = allowView;
                permission.Clone             = allowView;
                permission.DeleteMyTemplates = allowView;
                permission.Edit              = allowView;
                permission.List              = allowView;
                break;
            }
            if (permission == null)
            {
                permission = new ModuleGenericTemplateMessages(moduleCode);
            }
            return(permission);
        }
Exemplo n.º 10
0
        public List <TicketFile> AttachmentsLinkFiles(Message message, List <ModuleActionLink> links)
        {
            List <TicketFile> attachments = null;

            if (message == null || links == null || !links.Any())
            {
                return(null);
            }

            TicketUser usr = this.UserGetfromPerson(UC.CurrentUserID);

            if (message.Creator == null || message.Creator.Id != usr.Id)
            {
                return(null);
            }

            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                litePerson person = CurrentLitePerson;

                if (person != null && person.Id > 0)
                {
                    DateTime date = DateTime.Now;
                    attachments = new List <TicketFile>();
                    foreach (ModuleActionLink link in links)
                    {
                        TicketFile attachment = QueryAttachments(a => a.Deleted == BaseStatusDeleted.None && a.Message != null && a.Message.Id == message.Id).ToList().Where(a => a.Item == (liteRepositoryItem)link.ModuleObject.ObjectOwner).Skip(0).Take(1).ToList().FirstOrDefault();
                        if (attachment == null)
                        {
                            attachment = new TicketFile();
                            attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                            attachment.Item       = (liteRepositoryItem)link.ModuleObject.ObjectOwner;
                            attachment.Message    = message;
                            attachment.TicketId   = ((message != null && message.Ticket != null) ? message.Ticket.Id : 0);
                            attachment.Name       = attachment.Item.DisplayName;
                            attachment.Visibility = Domain.Enums.FileVisibility.visible;

                            Manager.SaveOrUpdate(attachment);


                            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(message.Id, message, (int)ModuleTicket.ObjectType.Message, 0, ModuleTicket.UniqueCode, 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();
                }
            }
            catch (Exception ex)
            {
                if (!isInTransaction)
                {
                    Manager.RollBack();
                }
                attachments = null;
            }
            return(attachments);
        }
Exemplo n.º 11
0
        public List <TicketFile> AttachmentsAddFiles(Message message, TicketUser user, List <dtoModuleUploadedItem> items)
        {
            List <TicketFile> attachments = null;

            if (message == null || message.Ticket == null || user == null || items == null || !items.Any())
            {
                return(null);
            }
            if (message.Creator == null || message.Creator.Id != user.Id)
            {
                return(null);
            }
            Boolean isInTransaction = Manager.IsInTransaction();

            try
            {
                if (!isInTransaction)
                {
                    Manager.BeginTransaction();
                }
                litePerson person = (user.Person ?? Manager.GetLiteUnknownUser());
                if (items.Any() && person != null && person.TypeID != (int)UserTypeStandard.Guest && person.TypeID != (int)UserTypeStandard.PublicUser)
                {
                    attachments = new List <TicketFile>();
                    DateTime date = DateTime.Now;
                    foreach (dtoModuleUploadedItem item in items)
                    {
                        TicketFile attachment = new TicketFile();
                        attachment.CreateMetaInfo(person, UC.IpAddress, UC.ProxyIpAddress, date);
                        attachment.Item       = item.ItemAdded;
                        attachment.Message    = message;
                        attachment.TicketId   = ((message != null && message.Ticket != null) ? message.Ticket.Id : 0);
                        attachment.Name       = attachment.Item.DisplayName;
                        attachment.Visibility = Domain.Enums.FileVisibility.visible;
                        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(message.Id, message, (int)ModuleTicket.ObjectType.Message, 0, ModuleTicket.UniqueCode, 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     = message.Id;
                            item.ItemAdded.Module.IdObjectType = (int)ModuleTicket.ObjectType.Message;
                            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);
        }