public void PoleXml_DeserializesTo_MeteredSpacePOST() { var serializer = new DataContractSerializer(typeof(MeteredSpacePOST)); string xml = @"<Pole> <Area>WILSHIRE</Area> <Lat>34.026239</Lat> <Long>-118.489714</Long> <PoleSerialNumber>WIL1301</PoleSerialNumber> <Status>1</Status> <SubArea>1301 WILSHIRE BLVD</SubArea> <Zone>Santa Monica, CA Default Zone</Zone> </Pole> "; MeteredSpacePOST pole = null; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(xml))) { pole = serializer.ReadObject(ms) as MeteredSpacePOST; } Assert.NotNull(pole); Assert.AreEqual("WILSHIRE", pole.Area); Assert.AreEqual(34.026239m, pole.Lat); Assert.AreEqual(-118.489714m, pole.Long); Assert.AreEqual("WIL1301", pole.PoleSerialNumber); Assert.AreEqual(1, pole.Status); Assert.AreEqual("1301 WILSHIRE BLVD", pole.SubArea); Assert.AreEqual("Santa Monica, CA Default Zone", pole.Zone); }
public MeteredSpace AddOrUpdate(MeteredSpacePOST viewModel) { var posted = new MeteredSpace() { MeterId = viewModel.PoleSerialNumber, Area = viewModel.Area, SubArea = viewModel.SubArea, Zone = viewModel.Zone, Latitude = viewModel.Lat, Longitude = viewModel.Long, Active = viewModel.Status.HasValue ? !viewModel.Status.Equals(0) : default(bool?) }; var existing = Get(posted.MeterId); if (existing == null) { _meteredSpacesRepo.Create(posted); } else { posted.Id = existing.Id; posted.Area = posted.Area ?? existing.Area; posted.SubArea = posted.SubArea ?? existing.SubArea; posted.Zone = posted.Zone ?? existing.Zone; posted.Latitude = posted.Latitude ?? existing.Latitude; posted.Longitude = posted.Longitude ?? existing.Longitude; posted.Active = posted.Active ?? existing.Active; _meteredSpacesRepo.Update(posted); } //invalidate the cache now that there is new data _cacheService.Remove(cacheKey); return(posted); }