/// <summary> /// Validates the parameters required to populate a NewsSection entity and assign it to the News if required /// </summary> /// <param name="sectionParagraph"></param> /// <param name="sectionImageFooter"></param> /// <param name="sectionImage"></param> /// <param name="newsData"></param> /// <returns>A string with the assigned name to the saved image</returns> private string ValidateAndProcessSection(string sectionParagraph, string sectionImageFooter, HttpPostedFileBase sectionImage, News newsData) { string newSectionImageName = string.Empty; bool isEmptyParagraph = string.Equals(sectionParagraph, "<p><br></p>"); if (!isEmptyParagraph || sectionImage != null) { NewsSection section = new NewsSection { Paragraph = HttpUtility.HtmlEncode(sectionParagraph) }; if (sectionImage != null && sectionImage.ContentLength > 0) { section.Image = Guid.NewGuid().ToString() + Path.GetExtension(sectionImage.FileName); section.ImageFooter = sectionImageFooter ?? string.Empty; string _path = Path.Combine(Server.MapPath(ImageStoragePath), section.Image); sectionImage.SaveAs(_path); newSectionImageName = section.Image; } newsData.NewsSections.Add(section); } return(newSectionImageName); }
private static void AddSectionsToAllUsers() { NewsSection.AddSectionToAllUsers(); EventsSection.AddSectionToAllUsers(); BulletinsSection.AddSectionToAllUsers(); GroupsSection.AddSectionToAllUsers(); NotificationSettingsSection.AddSectionToAllUsers(); }
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { NewsSection.AddSectionToAllUsers(applicationContext); EventsSection.AddSectionToAllUsers(applicationContext); BulletinsSection.AddSectionToAllUsers(applicationContext); RegisterRoutes(); base.ApplicationStarted(umbracoApplication, applicationContext); }
public JsonResult AddNewsSection(NewsSection newsSection) { newsSection.OrganizationID = HCRGCLIENT.OrganizationID; if (newsSection.NewsSectionID == null || newsSection.NewsSectionID == 0) { newsSection.NewsSectionID = _NewsService.AddNewsSection(Mapper.Map <HCRGUniversityMgtApp.NEPService.NewsService.NewsSection>(newsSection)); newsSection.flag = true; } else { _NewsService.UpdateNewsSection(Mapper.Map <HCRGUniversityMgtApp.NEPService.NewsService.NewsSection>(newsSection)); newsSection.flag = false; } return(Json(newsSection, GlobalConst.Message.text_html)); }
public static void FilterBest(List <NewsStory> stories, NewsSection section, int numToPick) { List <NewsStory> list = stories.Where <NewsStory>((Func <NewsStory, bool>)(x => x.section == section)).ToList <NewsStory>(); list.OrderBy <NewsStory, float>((Func <NewsStory, float>)(x => x.weight * x.importance)); int num = 0; foreach (NewsStory newsStory in list) { if (num >= numToPick) { stories.Remove(newsStory); } ++num; } }
/// <summary> /// Observer Pattern example. In this example, we have a digital newspaper, which contains two sections: /// sports and politics. There are specific editors to every section, as well as readers interested in /// receiving notifications about new news items and changes on these news, according to sections they /// are interested. /// /// The observer is applied to notify all readers about changes and new items registered to sections they /// are interested in. /// /// In a real world application, you could apply this pattern to send e-mails for employees responsible /// for different areas of a company, when an item is sold, a costumer requests a product, etc. /// </summary> /// <param name="args"></param> static void Main(string[] args) { // Create all sections var sportsSection = new NewsSection("Sports Section"); var politicsSection = new NewsSection("Politics Section"); // Create the sections' readers. var sportsSectionReader = new Reader { Name = "Sports Reader" }; var politicsSectionReader = new Reader { Name = "Politics Reader" }; var bothSectionsReader = new Reader { Name = "Both Sections Reader" }; // Create the editors. var sportsEditor = new Editor { Name = "Sports Editor" }; var politicsEditor = new Editor { Name = "Politics Editor" }; // Register all readers to the respective section. sportsSection.RegisterReader(sportsSectionReader); sportsSection.RegisterReader(bothSectionsReader); politicsSection.RegisterReader(politicsSectionReader); politicsSection.RegisterReader(bothSectionsReader); // Two diffente news are created, registered to a section, and one on them is changed, so the readers receive notifications about the actions performed. var sportNews = sportsEditor.RegisterNewsFor(sportsSection, "Fictional Player is the new reinforcement of Fictional Team.", "Fictional Team has bought all rights from Other Team last week to have Fictional Player for two years."); var politicsNews = politicsEditor.RegisterNewsFor(politicsSection, "City hall starts new building construction on fictional address.", "Fictional City's city hall has started the construction of a new building..."); politicsNews.Synthesis = "Update: Fictional City's mayor will see the construction tomorrow, about 08:00 AM..."; politicsEditor.UpdateNewsFor(politicsSection, politicsNews); // Remove the reader interested in both sections from sports section, and then change the sports news to verify how the notification is handled. sportsSection.RemoveReader(bothSectionsReader); sportNews.Title = "Fictional Player surprises supporters on accepting proposal from Fictional Team."; sportsEditor.UpdateNewsFor(sportsSection, sportNews); Console.ReadKey(); }
private string ValidateAndProcessEditSection(bool isImageDirty, int sectionIdFromDB, string sectionParagraph, string sectionImageFooter, HttpPostedFileBase sectionImage, News newsData, News currentNewsData) { string newSectionImageName = string.Empty; var currentSectionFromDB = currentNewsData.NewsSections.Where(x => x.Id == sectionIdFromDB).FirstOrDefault(); if (currentSectionFromDB != null) // section already exist on DB { NewsSection section = new NewsSection { Paragraph = HttpUtility.HtmlEncode(sectionParagraph) }; if (isImageDirty && sectionImage != null && sectionImage.ContentLength > 0) { // delete previous image if (currentSectionFromDB != null) { string fileNameToDelete = currentSectionFromDB.Image; DeleteFile(fileNameToDelete); } // save new image section.Image = Guid.NewGuid().ToString() + Path.GetExtension(sectionImage.FileName); string _path = Path.Combine(Server.MapPath(ImageStoragePath), section.Image); sectionImage.SaveAs(_path); newSectionImageName = section.Image; } else { section.Image = currentSectionFromDB.Image; newSectionImageName = section.Image; } section.ImageFooter = sectionImageFooter ?? string.Empty;; newsData.NewsSections.Add(section); } else // is not an update, check if it qualifies as new section { bool isEmptyParagraph = string.Equals(sectionParagraph, "<p><br></p>"); if (!isEmptyParagraph || sectionImage != null) { NewsSection section = new NewsSection { Paragraph = HttpUtility.HtmlEncode(sectionParagraph) }; if (sectionImage != null && sectionImage.ContentLength > 0) { // save new image section.Image = Guid.NewGuid().ToString() + Path.GetExtension(sectionImage.FileName); section.ImageFooter = sectionImageFooter ?? string.Empty; string _path = Path.Combine(Server.MapPath(ImageStoragePath), section.Image); sectionImage.SaveAs(_path); newSectionImageName = section.Image; } section.Image = section.Image ?? string.Empty; section.ImageFooter = section.ImageFooter ?? string.Empty; newsData.NewsSections.Add(section); } } return(newSectionImageName); }