Exemplo n.º 1
0
        public void CreateBasicPlugg(PluggContainer p)
        {
            if (p.CultureCode == null || p.CultureCode == "")
                throw new Exception("Cannot Create Plugg. CutureCode cannot be null");

            if (p.TheTitle == null || p.TheTitle.Text == null || p.TheTitle.Text == "")
                throw new Exception("Cannot Save Plugg. Title cannot be null");

            p.ThePlugg.CreatedInCultureCode = p.CultureCode;
            p.ThePlugg.CreatedOnDate = DateTime.Now;
            p.ThePlugg.ModifiedByUserId = p.ThePlugg.CreatedByUserId;
            p.ThePlugg.ModifiedOnDate = p.ThePlugg.CreatedOnDate;
            p.ThePlugg.IsDeleted = false;
            p.ThePlugg.IsListed = true;
            rep.CreatePlugg(p.ThePlugg);

            //Save Title
            p.TheTitle.ItemId = p.ThePlugg.PluggId;
            p.TheTitle.ItemType = ETextItemType.PluggTitle;
            p.TheTitle.CultureCode = p.CultureCode;
            p.TheTitle.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
            p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId;
            p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
            SavePhTextInAllCc(p.TheTitle);  //Save or Update

            //Save Description
            if (p.TheDescription != null && p.TheDescription.Text != null && p.TheDescription.Text != "")
            {
                p.TheDescription.ItemId = p.ThePlugg.PluggId;
                p.TheDescription.ItemType = ETextItemType.PluggDescription;
                p.TheDescription.CultureCode = p.CultureCode;
                p.TheDescription.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
                p.TheDescription.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                p.TheDescription.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                SavePhTextInAllCc(p.TheDescription);
            }

            PluggComponent video = new PluggComponent();
            video.ComponentOrder = 1;
            video.ComponentType = EComponentType.YouTube;
            AddComponent(p, video);

            PluggComponent rrText = new PluggComponent();
            rrText.ComponentOrder = 2;
            rrText.ComponentType = EComponentType.RichRichText;
            p.TheComponents = null;
            AddComponent(p, rrText);

            //Create PluggPage
            DNNHelper d = new DNNHelper();
            string pageUrl = p.ThePlugg.PluggId.ToString();
            string pageName = pageUrl + ": " + p.TheTitle.Text;
            TabInfo newTab = d.AddPluggPage(pageName, pageUrl);
            p.ThePlugg.TabId = newTab.TabID;
            rep.UpdatePlugg(p.ThePlugg);
        }
Exemplo n.º 2
0
        public void SavePlugg(PluggContainer p, List<object> cs)
        {
            if (p.ThePlugg.CreatedInCultureCode != null && p.CultureCode != p.ThePlugg.CreatedInCultureCode)
                throw new Exception("Cannot use SavePlugg unless you are saving it in the creation language.");

            p.ThePlugg.CreatedInCultureCode = p.CultureCode;

            try
            {
                bool isNew = p.ThePlugg.PluggId == 0;

                //Temporary - to avoid login - remove soon
                p.ThePlugg.CreatedByUserId = 1;
                p.ThePlugg.ModifiedByUserId = 1;

                //Save Plugg entity
                p.ThePlugg.ModifiedOnDate = DateTime.Now;

                if (isNew)
                {
                    p.ThePlugg.CreatedOnDate = DateTime.Now;
                    rep.CreatePlugg(p.ThePlugg);
                }
                else
                    rep.UpdatePlugg(p.ThePlugg);

                //Save Title
                if (p.TheTitle == null || p.TheTitle.Text == null)
                    throw new Exception("Cannot Save Plugg. TheTitle cannot be null");

                if (p.TheTitle.TextId == 0)
                {
                    p.TheTitle.ItemId = p.ThePlugg.PluggId;
                    p.TheTitle.ItemType = ETextItemType.PluggTitle;
                    p.TheTitle.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
                    p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                }
                SavePhTextInAllCc(p.TheTitle);  //Save or Update

                if (p.TheDescription != null && p.TheDescription.Text != null)
                {
                    if (p.TheDescription.TextId == 0)
                    {
                        p.TheDescription.ItemId = p.ThePlugg.PluggId;
                        p.TheDescription.ItemType = ETextItemType.PluggDescription;
                        p.TheDescription.CultureCodeStatus = ECultureCodeStatus.InCreationLanguage;
                        p.TheDescription.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                        p.TheDescription.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    }
                    SavePhTextInAllCc(p.TheDescription);
                }

                int cmpOrder = 1;
                PluggComponent pc = new PluggComponent();
                pc.PluggId = p.ThePlugg.PluggId;
                foreach (object cmp in cs)
                {
                    pc.ComponentOrder = cmpOrder;
                    switch (cmp.GetType().Name)
                    {
                        case "PHText":
                            PHText theText = (PHText)cmp;
                            switch (theText.ItemType)
                            {
                                case ETextItemType.PluggComponentRichRichText:
                                    pc.ComponentType = EComponentType.RichRichText;
                                    break;
                                case ETextItemType.PluggComponentRichText:
                                    pc.ComponentType = EComponentType.RichText;
                                    break;
                                case ETextItemType.PluggComponentLabel:
                                    pc.ComponentType = EComponentType.Label;
                                    break;
                            }
                            rep.CreatePluggComponent(pc);
                            theText.ItemId = pc.PluggComponentId;
                            theText.CultureCode = p.ThePlugg.CreatedInCultureCode;
                            theText.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                            SavePhTextInAllCc(theText);
                            break;
                        case "PHLatex":
                            PHLatex theLatex = (PHLatex)cmp;
                            pc.ComponentType = EComponentType.Latex;
                            rep.CreatePluggComponent(pc);
                            theLatex.ItemId = pc.PluggComponentId;
                            theLatex.CultureCode = p.ThePlugg.CreatedInCultureCode;
                            theLatex.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                            SaveLatexTextInAllCc(theLatex);
                            break;
                        case "YouTube":
                            pc.ComponentType = EComponentType.YouTube;
                            rep.CreatePluggComponent(pc);
                            YouTube theVideo = (YouTube)cmp;
                            theVideo.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                            theVideo.PluggComponentId = pc.PluggComponentId;
                            SaveYouTube(theVideo);
                            break;
                    }
                    cmpOrder++;
                }

                //Create PluggPage
                DNNHelper d = new DNNHelper();
                string pageUrl = p.ThePlugg.PluggId.ToString();
                string pageName = pageUrl + ": " + p.TheTitle.Text;
                TabInfo newTab = d.AddPluggPage(pageName, pageUrl);
                p.ThePlugg.TabId = newTab.TabID;
                rep.UpdatePlugg(p.ThePlugg);
            }
            catch (Exception)
            {
                //Todo: Update
                //DeletePlugg(p.ThePlugg);
                throw;
            }
        }
Exemplo n.º 3
0
        public void SavePlugg(PluggContainer p)
        {
            try
            {
                bool isNew = p.ThePlugg.PluggId == 0;

                //Temporary - remove soon
                p.ThePlugg.Title = "Title no longer here";
                p.ThePlugg.CreatedByUserId = 1;
                p.ThePlugg.ModifiedByUserId = 1;

                if (isNew)
                    rep.CreatePlugg(p.ThePlugg);
                else
                    rep.UpdatePlugg(p.ThePlugg);

                //Todo: Update..
                p.TheTitle.ItemId = p.ThePlugg.PluggId;
                p.TheTitle.ItemType = ETextItemType.PluggTitle;
                p.TheTitle.CcStatus = ECCStatus.InCreationLanguage;
                p.TheTitle.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                p.TheTitle.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                SavePhText(p.TheTitle);

                //Todo: Update..
                if (p.TheHtmlText != null)
                {
                    p.TheHtmlText.ItemId = p.ThePlugg.PluggId;
                    p.TheHtmlText.ItemType = ETextItemType.PluggHtml;
                    p.TheHtmlText.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheHtmlText.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheHtmlText.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    SavePhText(p.TheHtmlText);
                }

                //Todo: Update..
                if (p.TheLatex != null)
                {
                    p.TheLatex.ItemId = p.ThePlugg.PluggId;
                    p.TheLatex.ItemType = ELatexType.Plugg;
                    p.TheLatex.CcStatus = ECCStatus.InCreationLanguage;
                    p.TheLatex.CreatedByUserId = p.ThePlugg.CreatedByUserId;
                    p.TheLatex.ModifiedByUserId = p.ThePlugg.ModifiedByUserId;
                    LatexToMathMLConverter myConverter = new LatexToMathMLConverter(p.TheLatex.Text);
                    myConverter.Convert();
                    p.TheLatex.HtmlText = myConverter.HTMLOutput;
                    SaveLatexText(p.TheLatex);
                }

                LocaleController lc = new LocaleController();
                var locales = lc.GetLocales(PortalID);
                foreach (var locale in locales)
                {
                    if (locale.Key != p.ThePlugg.CreatedInCultureCode)
                    {
                        GoogleTranslate(p.TheTitle, locale.Key);
                        if (p.TheHtmlText != null)
                            GoogleTranslate(p.TheHtmlText, locale.Key);
                        if (p.TheLatex != null)
                            GoogleTranslate(p.TheLatex, locale.Key);
                    }
                }

                //Create PluggPage
                DNNHelper d = new DNNHelper();
                string pageUrl = p.ThePlugg.PluggId.ToString();
                string pageName = pageUrl + ": " + p.TheTitle.Text;
                TabInfo newTab = d.AddPluggPage(pageName, pageUrl);
                p.ThePlugg.TabId = newTab.TabID;
                rep.UpdatePlugg(p.ThePlugg);
            }
            catch (Exception)
            {
                //Todo: Update
                DeletePlugg(p.ThePlugg);
                throw;
            }
        }