private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e) { foreach (var item in e.PublishedEntities) { if (item.ContentType.Alias == "materiale") { try { using (bywhoEntities db = new bywhoEntities()) { Materials mat = null; var id = item.GetValue <string>("materialeId"); mat = db.Materials.FirstOrDefault(x => x.Id.ToString() == id); if (mat == null) { mat = new Materials(); PopulateModel(item, mat, true); db.Materials.Add(mat); db.SaveChanges(); item.SetValue("materialeId", mat.Id.ToString()); sender.SaveAndPublish(item, raiseEvents: false); } else { PopulateModel(item, mat, true); db.SaveChanges(); } } } catch { } } } }
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e) { foreach (var item in e.PublishedEntities) { if (item.ContentType.Alias == "page") { try { bywhoEntities db = new bywhoEntities(); int pguid = item.GetValue <int>("pageId"); var topic = db.Topic.FirstOrDefault(x => x.Id == pguid); var baseURL = "/cms"; if (topic != null) { topic.Title = item.GetValue <string>("title"); topic.SystemName = item.GetValue <string>("systemName"); topic.BodyTekst = TemplateUtilities.ResolveMediaFromTextString(item.GetValue <string>("bodyText")); topic.IsPage = item.GetValue <bool>("isPage"); topic.SeoTitle = item.GetValue <string>("seoTitle"); topic.SeoDescription = item.GetValue <string>("seoDescription"); topic.SeoKeywords = item.GetValue <string>("seoKeywords"); topic.NoFollow = item.GetValue <bool>("noFollow"); db.SaveChanges(); } } catch (Exception ex) { } } } }
private void ContentService_Unpublished(IContentService sender, PublishEventArgs <Umbraco.Core.Models.IContent> e) { foreach (var item in e.PublishedEntities) { if (item.ContentType.Alias == "materiale") { try { try { using (bywhoEntities db = new bywhoEntities()) { Materials mat = null; var id = item.GetValue <string>("materialeId"); mat = db.Materials.FirstOrDefault(x => x.Id.ToString() == id); if (mat != null) { mat.Published = false; db.SaveChanges(); } } } catch { } } catch { } } } }
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e) { foreach (var item in e.PublishedEntities) { if (item.ContentType.Alias == "product") { try { bywhoEntities db = new bywhoEntities(); Guid pguid = Guid.Parse(item.GetValue <string>("productId")); var style = db.Styles.FirstOrDefault(x => x.Id == pguid); var baseURL = "/cms"; if (style != null) { style.Name = item.GetValue <string>("productName"); style.Description = item.GetValue <string>("description"); style.Price = item.GetValue <decimal>("price"); style.OldPrice = item.GetValue <decimal>("oldPrice"); style.Picture = baseURL + item.GetValue <string>("picture"); style.Poster = baseURL + item.GetValue <string>("poster"); style.AmountOfPictures = (int)item.GetValue <decimal>("amountOfPictures"); style.Published = item.GetValue <bool>("published"); style.HasText = item.GetValue <bool>("hasTextInStyle"); style.SeoTitle = item.GetValue <string>("seoTitle"); style.SeoDescription = item.GetValue <string>("seoDescription"); style.SeoKeywords = item.GetValue <string>("seoKeywords"); style.NoFollow = item.GetValue <bool>("noFollow"); db.SaveChanges(); } } catch (Exception ex) { } } } }
private void ContentService_Published(IContentService sender, ContentPublishedEventArgs e) { foreach (var item in e.PublishedEntities) { if (item.ContentType.Alias == "resource") { try { bywhoEntities db = new bywhoEntities(); string systemName = item.Name; var resource = db.Resources.FirstOrDefault(x => x.Name == systemName); if (resource != null) { resource.Value = item.GetValue <string>("text"); db.SaveChanges(); } } catch (Exception ex) { } } } }