public static Publisher Create(XElement xml, XNamespace ns) { Publisher publisher = new Publisher { ID = xml.Element(ns + "folderId").Value, Name = xml.Element(ns + "name").Value }; return publisher; }
// GET: Adspace public ActionResult Index(string site, DateTime start, DateTime stop) { // Sätter kultur samt nummerseparator var culture = new CultureInfo("sv-SE"); var numberCulture = (NumberFormatInfo)culture.NumberFormat.Clone(); numberCulture.NumberGroupSeparator = " "; _viewmodel.Culture = culture; _viewmodel.NumberCulture = numberCulture; var NTMpublisher = new Publisher { Name = "Alla siter", SiteGroup = "NTM", ID = "ntm", Adspaces = new List<Adspace>() }; // Hämtar alla publishers från Cxense _viewmodel.Publishers = _model.GetPublishers(); _viewmodel.Publishers.Insert(0, NTMpublisher); _viewmodel.Start = start; _viewmodel.Stop = stop; // Hämtar alla siter indelade i sitegrupper _viewmodel.Sites = _model.SetPublisherGroup(_viewmodel.Publishers).OrderBy(p => p.Name).ToList(); // Lägger till siten "NTM" manuellt, för att kunna lista alla adspaces under den. _viewmodel.Sites.Add(new PublisherGroup { Name = "NTM", Publishers = _viewmodel.Sites.SelectMany(p => p.Publishers).ToList(), }); _viewmodel.Sites.Where(s => s.Name == "NTM").FirstOrDefault().Publishers.Insert(0, NTMpublisher); // Om vald sitegrupp finns... if (site != null && _viewmodel.Sites.Where(p => p.Name.ToLower() == site.ToLower()).Count() > 0) { // ...hämta ut statistik för siterna i den valda sitegruppen if (site.ToLower() != "ntm") { _viewmodel.ChosenPublishers = _model.GetInventoryBySite(site, start, stop.AddDays(1), true); _viewmodel.ChosenPublishers.ForEach(x => { x.SiteGroup = site.ToUpper(); }); } else // Om NTM (= visa alla), hämta ut all data utifrån alla sitegroups (CO, PT...) { _viewmodel.ChosenPublishers = new List<Publisher>(); List<string> listOfPublisherGroups = _viewmodel.Publishers.Select(p => p.SiteGroup).Distinct().ToList(); foreach (var siteGroup in listOfPublisherGroups) { var publishersInSiteGroup = _model.GetInventoryBySite(siteGroup, start, stop.AddDays(1), true); publishersInSiteGroup.ForEach(x => { x.SiteGroup = siteGroup; }); _viewmodel.ChosenPublishers.AddRange(publishersInSiteGroup); } _viewmodel.ChosenPublishers.Insert(0, new Publisher { Name = "Alla siter", SiteGroup = "NTM", ID = "ntm", Adspaces = new List<Adspace>() }); } _viewmodel.SelectedSite = site.ToLower() != "ntm" ? _viewmodel.Sites.Where(p => p.Name.ToLower() == site.ToLower()).Select(s => s.Publishers).FirstOrDefault().FirstOrDefault().ID : "ntm";//_viewmodel.Sites.Where(p => p.Publishers.FirstOrDefault().SiteGroup.ToLower() == site.ToLower()).Select(s => s.Publishers).FirstOrDefault().FirstOrDefault().ID; } return View(_viewmodel); }
// Grupperar en publishers adspaces enligt listan "Formats" public List<List<Adspace>> GroupAdspaces(Publisher publisher) { // För varje resultat(bokad kampanj)... foreach (var result in publisher.Adspaces) { // ...sök igenom formatet för matchningar mot "Internetenhet" (för att sedan kunna gruppera dem efter formetet från listan "formats", och inte Format (t.ex. "Panorama 1 240") foreach (var format in formats) { if (result.Name.ToLower().Contains(format)) { result.FormatType = format; break; } } } var groupedResults = publisher.Adspaces.GroupBy(c => c.FormatType).Select(grp => grp.ToList()).ToList(); return groupedResults; }