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); } }
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); }
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); }
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); } } }
//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); } }
public void SetHtmlText(string htmlText) { TheHtmlText = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggHtml); }
public void SetTitle(string htmlText) { TheTitle = new PHText(htmlText, ThePlugg.CreatedInCultureCode, ETextItemType.PluggTitle); }
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 void UpdatePhText(PHText p) { using (IDataContext db = DataContext.Instance()) { var rep = db.GetRepository<PHText>(); rep.Update(p); } }
//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); } }
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); } }
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); }