//public void InitView(dtoDisplayItemRepository item)
        //{
        //    if (item == null)
        //        View.DisplayNoAction();
        //    else
        //        AnalyzeAction(item);
        //}

        private void AnalyzeAction(ModuleLink pLink)
        {
            int ActionID           = pLink.Action;
            BaseCommunityFile item = null;

            if ((pLink.DestinationItem != null))
            {
                item = Service.GetItem(pLink.DestinationItem.ObjectLongID);
                if ((item == null) || (pLink.DestinationItem.ObjectLongID == 0 && (ActionID == (int)CoreModuleRepository.ActionType.CreateFolder || ActionID == (int)CoreModuleRepository.ActionType.UploadFile)))
                {
                    View.DisplayRemovedObject();
                }
                else
                {
                    int IdCommunity = 0;
                    if (item.CommunityOwner != null)
                    {
                        IdCommunity = item.CommunityOwner.Id;
                    }
                    if (typeof(CommunityFile) == item.GetType())
                    {
                        View.ServiceCode = pLink.DestinationItem.ServiceCode;
                        View.ServiceID   = pLink.DestinationItem.ServiceID;
                    }
                    else
                    {
                        View.ServiceCode = pLink.SourceItem.ServiceCode;
                        View.ServiceID   = pLink.SourceItem.ServiceID;
                    }

                    if (item is ModuleInternalFile)
                    {
                        ModuleInternalFile oInternal = (ModuleInternalFile)item;
                        View.DisplayLinkForModule(pLink.Id, IdCommunity, item, oInternal.ServiceActionAjax);
                    }
                    else
                    {
                        View.DisplayLink(pLink.Id, IdCommunity, item);
                    }
                }
            }
            else
            {
                View.DisplayNoAction();
            }
        }
        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 Sub InitView(ByVal oItem As dtoCommunityItemRepository)
        //    Me.View.FileDisplayName = ""
        //    If oItem Is Nothing Then
        //        Me.View.DisplayNoAction()
        //    Else : AnalyzeAction(oItem)
        //    End If
        //End Sub

        public void AnalyzeAction(ModuleLink link, iCoreFilePermission permission)
        {
            Int32             idAction = link.Action;
            BaseCommunityFile item     = null;

            if (link.DestinationItem != null)
            {
                item = Service.GetItem(link.DestinationItem.ObjectLongID);
                if (item == null || (link.DestinationItem.ObjectLongID == 0 && (idAction == (Int32)CoreModuleRepository.ActionType.CreateFolder || idAction == (Int32)CoreModuleRepository.ActionType.UploadFile)))
                {
                    View.DisplayRemovedObject();
                }
                else
                {
                    Int32 idCommunity = 0;
                    switch (idAction)
                    {
                    case (Int32)CoreModuleRepository.ActionType.DownloadFile:
                        if (typeof(CommunityFile) == item.GetType())
                        {
                            View.ModuleCode = link.DestinationItem.ServiceCode;
                            View.IdModule   = link.DestinationItem.ServiceID;
                        }
                        else
                        {
                            View.ModuleCode = link.SourceItem.ServiceCode;
                            View.IdModule   = link.SourceItem.ServiceID;
                        }
                        if (item.CommunityOwner != null)
                        {
                            idCommunity = item.CommunityOwner.Id;
                        }

                        View.FileDisplayName = item.DisplayName;
                        View.DisplayLinkDownload(link.Id, idCommunity, item, permission);
                        break;

                    case (Int32)CoreModuleRepository.ActionType.PlayFile:

                        if (typeof(CommunityFile) == item.GetType())
                        {
                            View.ModuleCode = link.DestinationItem.ServiceCode;
                            View.IdModule   = link.DestinationItem.ServiceID;
                        }
                        else
                        {
                            View.ModuleCode = link.SourceItem.ServiceCode;
                            View.IdModule   = link.SourceItem.ServiceID;
                        }
                        if (item.CommunityOwner != null)
                        {
                            idCommunity = item.CommunityOwner.Id;
                        }
                        View.FileDisplayName = item.DisplayName;

                        if (typeof(ModuleInternalFile) == item.GetType())
                        {
                            ModuleInternalFile intItem = (ModuleInternalFile)item;
                            View.DisplayLinkForPlayInternal(link.Id, idCommunity, item, permission, intItem.ServiceActionAjax);
                        }
                        else
                        {
                            View.DisplayLinkForPlay(link.Id, idCommunity, item, permission);
                        }
                        break;

                    default:
                        View.DisplayNoAction();
                        break;
                    }
                }
            }
            else
            {
                View.DisplayNoAction();
            }
        }
        public void InitView()
        {
            int  IdUser      = UserContext.CurrentUserID;
            int  idCommunity = UserContext.CurrentCommunityID;
            long IdLink      = View.PreloadedIdLink;
            long IdFile      = View.PreloadedIdFile;

            View.BackUrl = View.PreloadedBackUrl;
            View.IdFile  = IdFile;
            View.IdLink  = IdLink;
            View.AllowSetDefaultDocument = false;
            BaseCommunityFile item = Service.GetItem(IdFile);

            if (item != null && item.CommunityOwner != null)
            {
                idCommunity = item.CommunityOwner.Id;
            }
            if (UserContext.isAnonymous)
            {
                View.SendToSessionExpiredPage(idCommunity, UserContext.Language.Code);
            }
            else if (item == null)
            {
                View.LoadFileNotExist();
            }
            else if (item.RepositoryItemType == RepositoryItemType.Multimedia)
            {
                RepositoryItemPermission permissions = new RepositoryItemPermission();
                if (IdLink == 0 || item.GetType() == typeof(CommunityFile))
                {
                    CoreModuleRepository module = null;
                    if (item.CommunityOwner == null)
                    {
                        module = CoreModuleRepository.CreatePortalmodule(UserContext.UserTypeID);
                    }
                    else if (!item.IsInternal)
                    {
                        module = new CoreModuleRepository(CurrentManager.GetModulePermission(IdUser, item.CommunityOwner.Id, ModuleID));
                    }
                    else
                    {
                        module = new CoreModuleRepository();
                    }
                    if (Service.HasPermissionToSeeRepositoryItem(item.Id, module.Administration, module.Administration, IdUser))
                    {
                        permissions = new dtoDisplayItemRepository(item, module, IdUser, module.Administration).Permission;
                    }
                }
                else
                {
                    ModuleLink link = Service.GetModuleLink(IdLink);
                    permissions = View.GetModuleLinkPermission(link.SourceItem.CommunityID, IdUser, link);
                }
                if (permissions.EditSettings)
                {
                    MultimediaFileTransfer multimedia = Service.GetMultimediaFileTransfer(item);
                    if (multimedia == null)
                    {
                        View.LoadFileNotExist();
                    }
                    else if (multimedia.MultimediaIndexes.Count == 0)
                    {
                        View.LoadFileWithoutIndex(item);
                    }
                    else
                    {
                        View.AllowSetDefaultDocument = permissions.EditSettings;
                        View.LoadTree(item, (from m in multimedia.MultimediaIndexes select m.Fullname.Replace(item.UniqueID.ToString() + "\\", "")).ToList(), (multimedia.DefaultDocument == null) ? "" : multimedia.DefaultDocument.Fullname.Replace(item.UniqueID.ToString() + "\\", ""));
                    }
                }
                else
                {
                    View.LoadFileNoPermission();
                }
            }
            else
            {
                View.LoadInvalidFileType(item);
            }
        }