public void CreatePhText(PHText p)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <PHText>();
         rep.Insert(p);
     }
 }
 public void DeletePhText(PHText p)
 {
     using (IDataContext db = DataContext.Instance())
     {
         var rep = db.GetRepository <PHText>();
         rep.Delete(p);
     }
 }
 public void CreatePhText(PHText p)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<PHText>();
         rep.Insert(p);
     }
 }
示例#4
0
        public void LoadHtmlText()
        {
            if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
            {
                throw new Exception("Cannot laod HtmlText. Need PluggId and CultureCode");
            }
            BaseRepository rep = new BaseRepository();

            TheHtmlText = rep.GetPhText(CultureCode, ThePlugg.PluggId, (int)ETextItemType.PluggHtml);
        }
示例#5
0
        public void LoadTitle()
        {
            if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
            {
                throw new Exception("Cannot load title. Need PluggId and CultureCode");
            }
            BaseRepository rep = new BaseRepository();

            TheTitle = rep.GetPhText(CultureCode, ThePlugg.PluggId, (int)ETextItemType.PluggTitle);
        }
        public PHText GetPhText(string cultureCode, int itemId, int itemType)
        {
            IEnumerable <PHText> txt;
            PHText theText = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <PHText>();
                txt = rep.Find("WHERE CultureCode = @0 AND ItemId = @1 AND ItemType = @2", cultureCode, itemId, itemType);
            }

            if (txt.Any())
            {
                theText = txt.First(); //Can only be at most one. PetaPoco does not handle composite key
            }
            return(theText);
        }
示例#7
0
        public void SavePhText(PHText t)
        {
            if (t.Text == null || t.ItemId == 0 || t.ItemType == ETextItemType.NotSet || t.CultureCode == null || t.CcStatus == ECCStatus.NotSet || t.CreatedByUserId == 0)
            {
                throw new Exception("Cannot save text - need Text, ItemId, ItemType, CultureCode, CreatedByUserId and CcStatus");
            }

            if (t.ModifiedByUserId == 0)
            {
                t.ModifiedByUserId = t.CreatedByUserId;
            }
            t.ModifiedOnDate = DateTime.Now;
            t.CurrentVersion = true;
            bool isVersioned = t.ItemType == ETextItemType.PluggHtml;

            if (isVersioned)
            {
                var prevText = rep.GetPhText(t.CultureCode, t.ItemId, (int)t.ItemType);
                if (prevText == null)
                {
                    t.Version = 1;
                }
                else
                {
                    t.Version = prevText.Version++;
                    prevText.CurrentVersion = false;
                    rep.UpdatePhText(prevText);
                }
                t.CreatedOnDate = DateTime.Now;
                rep.CreatePhText(t);
            }
            else
            {
                t.Version = 0;
                if (t.TextId == 0)
                {
                    t.CreatedOnDate = DateTime.Now;
                    rep.CreatePhText(t);
                }
                else
                {
                    rep.UpdatePhText(t);
                }
            }
        }
示例#8
0
        //translates t into culture code cc
        public void GoogleTranslate(PHText t, string cc)
        {
            if (t.CultureCode == cc)
            {
                throw new Exception("Cannot translate text to the same language");
            }

            PHText currentText = rep.GetPhText(cc, t.ItemId, (int)t.ItemType);

            if (currentText == null)
            {
                t.Text = TranslateText(t.CultureCode, cc, t.Text) ?? t.Text;
                //Todo: Translate. For now: same
                t.CultureCode = cc;
                //t.Text = (Translation of t.Text from t.CultureCode into cc)
                rep.CreatePhText(t);
            }
            else
            {
                currentText.Text = t.Text;
                rep.UpdatePhText(currentText);
            }
        }
示例#9
0
 public void SetHtmlText(string htmlText)
 {
     TheHtmlText = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggHtml);
 }
示例#10
0
 public void SetTitle(string htmlText)
 {
     TheTitle = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggTitle);
 }
示例#11
0
 public void LoadTitle()
 {
     if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
         throw new Exception("Cannot load title. Need PluggId and CultureCode");
     BaseRepository rep = new BaseRepository();
     TheTitle = rep.GetPhText(CultureCode, ThePlugg.PluggId, (int)ETextItemType.PluggTitle);
 }
示例#12
0
 public void UpdatePhText(PHText p)
 {
     using (IDataContext db = DataContext.Instance())
     {
         var rep = db.GetRepository<PHText>();
         rep.Update(p);
     }
 }
示例#13
0
 public void SetTitle(string htmlText)
 {
     TheTitle = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggTitle);
 }
示例#14
0
 public void SetHtmlText(string htmlText)
 {
     TheHtmlText = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggHtml);
 }
示例#15
0
        //translates t into culture code cc
        public void GoogleTranslate(PHText t, string cc)
        {
            if (t.CultureCode == cc)
                throw new Exception("Cannot translate text to the same language");

            PHText currentText = rep.GetPhText(cc, t.ItemId, (int)t.ItemType);

            if (currentText == null)
            {
                t.Text = TranslateText(t.CultureCode, cc, t.Text)??t.Text;
                //Todo: Translate. For now: same
                t.CultureCode = cc;
                //t.Text = (Translation of t.Text from t.CultureCode into cc)
                rep.CreatePhText(t);
            }
            else
            {
                currentText.Text = t.Text;
                rep.UpdatePhText(currentText);
            }
        }
示例#16
0
        public void SavePhText(PHText t)
        {
            if (t.Text == null || t.ItemId == 0 || t.ItemType == ETextItemType.NotSet || t.CultureCode == null || t.CcStatus == ECCStatus.NotSet || t.CreatedByUserId == 0)
                throw new Exception("Cannot save text - need Text, ItemId, ItemType, CultureCode, CreatedByUserId and CcStatus");

            if (t.ModifiedByUserId == 0)
                t.ModifiedByUserId = t.CreatedByUserId;
            t.ModifiedOnDate = DateTime.Now;
            t.CurrentVersion = true;
            bool isVersioned = t.ItemType == ETextItemType.PluggHtml;

            if (isVersioned)
            {
                var prevText = rep.GetPhText(t.CultureCode, t.ItemId, (int)t.ItemType);
                if (prevText == null)
                {
                    t.Version = 1;
                }
                else
                {
                    t.Version = prevText.Version++;
                    prevText.CurrentVersion = false;
                    rep.UpdatePhText(prevText);
                }
                t.CreatedOnDate = DateTime.Now;
                rep.CreatePhText(t);
            }
            else
            {
                t.Version = 0;
                if (t.TextId == 0)
                {
                    t.CreatedOnDate = DateTime.Now;
                    rep.CreatePhText(t);
                }
                else
                    rep.UpdatePhText(t);
            }
        }
示例#17
0
 public void LoadHtmlText()
 {
     if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
         throw new Exception("Cannot laod HtmlText. Need PluggId and CultureCode");
     BaseRepository rep = new BaseRepository();
     TheHtmlText = rep.GetPhText(CultureCode, ThePlugg.PluggId, (int)ETextItemType.PluggHtml);
 }