public void DeleteLatexText(PHLatex p)
 {
     using (IDataContext db = DataContext.Instance())
     {
         var rep = db.GetRepository <PHLatex>();
         rep.Delete(p);
     }
 }
 public void CreateLatexText(PHLatex p)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository<PHLatex>();
         rep.Insert(p);
     }
 }
 public void CreateLatexText(PHLatex p)
 {
     using (IDataContext ctx = DataContext.Instance())
     {
         var rep = ctx.GetRepository <PHLatex>();
         rep.Insert(p);
     }
 }
Exemple #4
0
        public void LoadLatexText()
        {
            if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
            {
                throw new Exception("Cannot load Latex. Need PluggId and CultureCode");
            }
            BaseRepository rep = new BaseRepository();

            TheLatex = rep.GetLatexText(CultureCode, ThePlugg.PluggId, (int)ELatexType.Plugg);
        }
        public PHLatex GetLatexText(string cultureCode, int itemId, int itemType)
        {
            IEnumerable <PHLatex> txt;
            PHLatex theText = null;

            using (IDataContext ctx = DataContext.Instance())
            {
                var rep = ctx.GetRepository <PHLatex>();
                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);
        }
        public void SaveLatexText(PHLatex t)
        {
            if (t.Text == null || t.ItemId == 0 || t.ItemType == ELatexType.NotSet || t.CultureCode == null || t.CcStatus == ECCStatus.NotSet || t.CreatedByUserId == 0)
            {
                throw new Exception("Cannot save Latex - 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 == ELatexType.Plugg || t.ItemType == ELatexType.Course);

            if (isVersioned)
            {
                var prevText = rep.GetLatexText(t.CultureCode, t.ItemId, (int)t.ItemType);
                if (prevText == null)
                {
                    t.Version = 1;
                }
                else
                {
                    t.Version = prevText.Version++;
                    prevText.CurrentVersion = false;
                    rep.UpdateLatexText(prevText);
                }
                t.CreatedOnDate = DateTime.Now;
                rep.CreateLatexText(t);
            }
            else
            {
                t.Version = 0;
                if (t.LatexId == 0)
                {
                    t.CreatedOnDate = DateTime.Now;
                    rep.CreateLatexText(t);
                }
                else
                {
                    rep.UpdateLatexText(t);
                }
            }
        }
        //translates t into culture code cc
        public void GoogleTranslate(PHLatex t, string cc)
        {
            if (t.CultureCode == cc)
            {
                throw new Exception("Cannot translate text to the same language");
            }

            PHLatex currentText = rep.GetLatexText(cc, t.ItemId, (int)t.ItemType);

            if (currentText == null)
            {
                //Todo: Translate. For now: same
                t.CultureCode = cc;
                //t.Text = (Translation of t.Text from t.CultureCode into cc)
                rep.CreateLatexText(t);
            }
            else
            {
                currentText.Text = t.Text;
                rep.UpdateLatexText(currentText);
            }
        }
        public void SaveLatexText(PHLatex t)
        {
            if (t.Text == null || t.ItemId == 0 || t.ItemType == ELatexType.NotSet || t.CultureCode == null || t.CcStatus == ECCStatus.NotSet || t.CreatedByUserId == 0)
                throw new Exception("Cannot save Latex - 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 == ELatexType.Plugg || t.ItemType == ELatexType.Course);

            if (isVersioned)
            {
                var prevText = rep.GetLatexText(t.CultureCode, t.ItemId, (int)t.ItemType);
                if (prevText == null)
                {
                    t.Version = 1;
                }
                else
                {
                    t.Version = prevText.Version++;
                    prevText.CurrentVersion = false;
                    rep.UpdateLatexText(prevText);
                }
                t.CreatedOnDate = DateTime.Now;
                rep.CreateLatexText(t);
            }
            else
            {
                t.Version = 0;
                if (t.LatexId == 0)
                {
                    t.CreatedOnDate = DateTime.Now;
                    rep.CreateLatexText(t);
                }
                else
                    rep.UpdateLatexText(t);
            }
        }
        //translates t into culture code cc
        public void GoogleTranslate(PHLatex t, string cc)
        {
            if (t.CultureCode == cc)
                throw new Exception("Cannot translate text to the same language");

            PHLatex currentText = rep.GetLatexText(cc, t.ItemId, (int)t.ItemType);

            if (currentText == null)
            {
                //Todo: Translate. For now: same
                t.CultureCode = cc;
                //t.Text = (Translation of t.Text from t.CultureCode into cc)
                rep.CreateLatexText(t);
            }
            else
            {
                currentText.Text = t.Text;
                rep.UpdateLatexText(currentText);
            }
        }
Exemple #10
0
 public void SetLatexText(string htmlText)
 {
     TheLatex = new PHLatex(htmlText, ThePlugg.CreatedInCultureCode, ELatexType.Plugg);
 }
 public void UpdateLatexText(PHLatex p)
 {
     using (IDataContext db = DataContext.Instance())
     {
         var rep = db.GetRepository<PHLatex>();
         rep.Update(p);
     }
 }
 public void SetLatexText(string htmlText)
 {
     TheLatex = new PHLatex(htmlText, ThePlugg.CreatedInCultureCode, ELatexType.Plugg);
 }
 public void LoadLatexText()
 {
     if (ThePlugg == null || ThePlugg.PluggId == 0 || CultureCode == null)
         throw new Exception("Cannot load Latex. Need PluggId and CultureCode");
     BaseRepository rep = new BaseRepository();
     TheLatex = rep.GetLatexText(CultureCode, ThePlugg.PluggId, (int)ELatexType.Plugg);
 }