Ejemplo n.º 1
0
        public ActionResult Create(Station station)
        {
            if (ModelState.IsValid)
            {
                _licenceService.Add(station);
                _licenceService.SaveChanges();
                TempData["Success"] = true;
                return RedirectToAction("Index");
            }

            return View(station);
        }
        private void importStations(XDocument doc, ILicenceService service)
        {
            var stations = new List<Station>();

            foreach(var x in doc.Descendants("stations"))
            {
                var station = new Station
                {
                    Location = x.Element("location").Value,
                    ProvinceCode = x.Element("province_code").Value,
                    Latitude = (decimal)x.Element("latitude"),
                    Longitude = (decimal)x.Element("longitude"),
                    SiteElevation = (int)x.Element("site_elevation"),
                    StructureHeight = (int)x.Element("structure_height"),
                    ZoneEnhancerIndicator = x.Element("zone_enhancer_indicator").Value,
                    DateLastModifications = Convert.ToDateTime(x.Element("date_last_modifications").Value),
                    Channels = loadChannels(x)
                };

                var match = stations.FirstOrDefault(y => y.Location == station.Location);

                if (match == null)
                {
                    stations.Add(station);
                }
                else
                {
                    foreach (var channel in station.Channels)
                    {
                        if (!match.Channels.Any(c => c.TxAntAzimuth == channel.TxAntAzimuth))
                        {
                            match.Channels.Add(channel);
                        }
                    }
                }
            }

            foreach (var station in stations)
            {
                service.Add(station);
            }

            service.SaveChanges();
        }