Exemplo n.º 1
0
        public ActionResult Create(Licence licence)
        {
            if (ModelState.IsValid)
            {
                _service.Add(licence);
                _service.SaveChanges();
                TempData["Success"] = true;
                return RedirectToAction("Index");
            }

            return View(licence);
        }
Exemplo n.º 2
0
 private IEnumerable<XElement> getStations(Licence licence)
 {
     var results = from x in licence.Channels
                   group x by x.Station.Id into xGroup
                   let station = xGroup.FirstOrDefault().Station
                   select new XElement("stations",
                          new XElement("location", station.Location),
                          new XElement("province_code", station.ProvinceCode),
                          new XElement("latitude", station.Latitude),
                          new XElement("longitude", station.Longitude),
                          new XElement("site_elevation", station.SiteElevation),
                          new XElement("structure_height", station.StructureHeight),
                          new XElement("zone_enhancer_indicator", "N"),
                          new XElement("date_last_modifications", DateTime.UtcNow.ToString("yyyy-MM-dd")),
                       //new XElement("nad27_83", site.NAD_27_83),
                          getChannels(xGroup)
                       );
     //return results.Take(1);
     return results;
 }
        public void Can_Import_Station_Data()
        {
            var doc = XDocument.Load(@"C:\Temp\Silo_Station_Data.xml");
            var service = new LicenceService();

            importStations(doc, service);

            foreach(var x in doc.Descendants("spectrum_licence"))
            {
                var licence = new Licence
                {
                    Name = getLicenceName(x.Element("licence_number")),
                    Number = (int)x.Element("licence_number"),
                    OfficeNumber = (int)x.Element("office_number"),
                    CompanyCode = (int)x.Element("company_code"),
                    ReferenceNumber = x.Element("reference_number").Value,
                    ContactName = x.Element("contact_name").Value,
                    BusinessTelephone = (long)x.Element("business_telephone"),
                    Extension = (int?)x.Element("extension") ?? null,
                    Email = x.Element("email_address").Value
                };

                foreach (var stationElem in x.Descendants("stations"))
                {
                    var location = stationElem.Element("location").Value;

                    foreach (var channel in stationElem.Descendants("channels"))
                    {
                        var azimuth = (decimal)channel.Element("tx_ant_azimuth");

                        try
                        {
                            var match = service.Channels
                                .Where(c => c.Station.Location == location)
                                .Where(c => c.TxAntAzimuth == azimuth)
                                .Single();

                            if (licence.Channels == null)
                            {
                                licence.Channels = new List<Channel> { match };
                            }
                            else
                            {
                                licence.Channels.Add(match);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                }

                service.Add(licence);
            }

            service.SaveChanges();

            var target = service.Licences;
            Assert.AreEqual(5, target.Count());
        }