public static void CopyArticle(int TemplateID, int ArticleId, string name, int Office_Sequence, string Content, byte[] ContentImage) { using (var db = new Database(DbConfiguration.LtcNewsletter)) { var categoryId = 1; gArticleModel art = db.Fetch <gArticleModel>($"select * from system_articles where ArticleID={ArticleId}").FirstOrDefault(); if (art != null) { categoryId = art.CategoryID; } gSavePredefinedTemplate found = db.Fetch <gSavePredefinedTemplate>($"select * from templates where TemplateID={TemplateID}").FirstOrDefault(); if (found != null) { gSaveUserTemplate obj = new gSaveUserTemplate(); obj.TemplateTitle = name; obj.Office_Sequence = Office_Sequence; obj.EmbeddedNewsletter = string.Empty; obj.MainBodymarkup = Content; obj.TemplateSourceMarkup = found.TemplateSourceMarkup; obj.TypeID = 8; obj.ThumbnailPath = found.ThumbnailPath; obj.ContentImage = ContentImage; obj.ModificationDate = DateTime.Now.ToUniversalTime(); obj.CategoryID = categoryId; db.Save(obj); } } }
public static void UpdateLetter(gLetterModelTest model) { using (var db = new Database(DbConfiguration.LtcNewsletter)) { gSaveUserTemplate found = db .Fetch <gSaveUserTemplate>($"select * from templates_user where LetterID={model.LetterID}") .FirstOrDefault(); byte[] byteArray = Convert.FromBase64String(model.ContentImage); found.ContentImage = byteArray; if (found != null) { db.Update(found, model.LetterID); } //else // db.Save(model); } }
public static void DeleteUserDefinedTemplate(int Id) { using (var db = new Database(DbConfiguration.LtcNewsletter)) { gSaveUserTemplate found = db.Fetch <gSaveUserTemplate>($"select * from templates_user where LetterID={Id}").FirstOrDefault(); if (found != null) { if (found.IsDefault) { gSaveUserTemplate firstSystemTemplate = db.Fetch <gSaveUserTemplate>($"select * from templates_user where TypeID ={found.TypeID} AND Office_Sequence = {found.Office_Sequence} AND IsParadigmNewsletter = 1 limit 1").FirstOrDefault(); if (firstSystemTemplate != null) { db.Execute($"Update templates_user Set IsDefault = 1 WHERE LetterID = {firstSystemTemplate.LetterID} AND Office_Sequence = {found.Office_Sequence} "); } } } db.Delete("templates_user", "LetterID", new gGetUserDefinedTemplateModel { LetterID = Id }); } }
public static bool MakeDefault(int TemplateID, bool IsDefault) { using (var db = new Database(DbConfiguration.LtcNewsletter)) { gSaveUserTemplate found = db.Fetch <gSaveUserTemplate>($"select * from templates_user where LetterID={TemplateID}").FirstOrDefault(); if (found != null) { if (found.IsDefault && !IsDefault) { return(false); } else { db.Execute($"Update templates_user Set IsDefault = 0 WHERE TypeID = {found.TypeID} AND Office_Sequence = {found.Office_Sequence} "); db.Execute($"Update templates_user Set IsDefault = {IsDefault}, ModificationDate = '{DateTime.Now.ToUniversalTime().ToString("yyyy-MM-dd")}' Where LetterID={TemplateID} "); return(true); } } } return(true); }
public static void CopySystemTemplate(int TemplateID, string name, int Office_Sequence) { using (var db = new Database(DbConfiguration.LtcNewsletter)) { gSavePredefinedTemplate found = db.Fetch <gSavePredefinedTemplate>($"select * from templates where TemplateID={TemplateID}").FirstOrDefault(); if (found != null) { gSaveUserTemplate obj = new gSaveUserTemplate(); obj.TemplateTitle = name; obj.Office_Sequence = Office_Sequence; //obj.ContentImage = found //obj.IndustryID = found.IndustryID; obj.MainBodymarkup = found.TemplateSourceMarkup; obj.TemplateSourceMarkup = found.TemplateSourceMarkup; obj.TypeID = 8; obj.ThumbnailPath = found.ThumbnailPath; obj.ModificationDate = DateTime.Now.ToUniversalTime(); obj.CategoryID = 1; db.Save(obj); } } }
public static bool SaveUserNewsTemplate(gSaveUserTemplate model) { //gArticleModel article = new gArticleModel(); //article.Content = model.MainBodymarkup; //article.ModificationDate = DateTime.Now; //article.Title = model.TemplateTitle; //using (var db = new Database(DbConfiguration.LtcNewsletter)) //{ // db.Insert(article); //} if (model.TypeID == 0) { model.TypeID = 1; } model.TemplateSourceMarkup = model.TemplateSourceMarkup ?? "empty"; using (var db = new Database(DbConfiguration.LtcNewsletter)) { gSaveUserTemplate found = db.Fetch <gSaveUserTemplate>($"select * from templates_user where LetterID={model.LetterID}").FirstOrDefault(); if (!model.IsParadigmNewsletter) { var Count = db .Fetch <gSaveUserTemplate>( $"select LetterID from templates_user where TypeID={model.TypeID} AND Office_Sequence={model.Office_Sequence} AND IsParadigmNewsletter = 1 ") .Count(); if (Count < 1) { model.IsParadigmNewsletter = true; } if (found != null) { if ((found.IsParadigmNewsletter && found.IsDefault) && !model.IsParadigmNewsletter) { return(false); } } } if (model.IsParadigmNewsletter) { if (!model.IsDefault) { var Count = db.Fetch <gSaveUserTemplate>($"select LetterID from templates_user where TypeID={model.TypeID} AND Office_Sequence={model.Office_Sequence} AND IsParadigmNewsletter = 1 AND IsDefault = 1").Count(); if (Count < 1) { model.IsDefault = true; } } } if (model.IsDefault && found != null) { db.Execute($"Update templates_user Set IsDefault = 0 where TypeID = {model.TypeID} AND IsParadigmNewsletter = 1 AND Office_Sequence = {found.Office_Sequence} "); } model.ModificationDate = DateTime.Now.ToUniversalTime(); if (model.TypeID == 8) { model.IsDefault = false; model.IsParadigmNewsletter = false; } if (found != null) { db.Update(model, model.LetterID); } else { model.TemplateSourceMarkup = model.MainBodymarkup; db.Save(model); } } return(true); }