public void Update(SupplementalObservation observation) { observation.SpeciesCode = observation.SpeciesCode.ToUpper(); ObservationMapper.Update(observation); _state.SiteVisit.SupplementalObservations.RemoveAll(x => x.Id.Equals(observation.Id)); _state.SiteVisit.SupplementalObservations.Add(observation); }
public void t_PointCountLess50_Save_Update() { //loadSiteVisit(TestHelper.TestGuid1); Observation_ado setupObject = null; // backdoor data setup DbTestHelper.LoadAdoObjects(delegate(IbaUnitTestEntities iba) { setupObject = new Observation_ado() { Comments = "asdfasdf asdf adsfa dsfads fasdf adsfasd fadsf awefr34fr34r34 ", SpeciesId = new Guid(TestHelper.SPECIES_1_ID), EventId = TestHelper.TestGuid1, ObservationTypeId = _PointCountLess50TypeId }; iba.AddToObservation_ado(setupObject); }); List <Observation_ado> extraList = DbTestHelper.LoadExtraneousObservations(TestHelper.TestGuid3); // Setup object to be saved. Change everything except the Id. PointCountWithin50 testObject = new PointCountWithin50() { Comments = "hurdy gurdy", SpeciesCode = TestHelper.SPECIES_2_CODE, EventId = setupObject.EventId, Id = setupObject.ObservationId }; // Execute the test ObservationMapper.Update(testObject); // Validate results using (IbaUnitTestEntities iba = new IbaUnitTestEntities()) { var PointCountLess50Query = from PointCountLess50s in iba.Observation_ado select PointCountLess50s; Assert.IsNotNull(PointCountLess50Query, "Query result is null"); Assert.AreEqual(extraList.Count() + 1, PointCountLess50Query.Count(), "Wrong number of results in query"); Observation_ado adoPointCountLess50 = PointCountLess50Query.First(x => x.ObservationId == setupObject.ObservationId); validateObjectEquality(testObject, adoPointCountLess50, iba); validateExtraObservations(extraList, PointCountLess50Query); } }
public void Update(FiftyMeterDataEntry entry) { entry.SpeciesCode = entry.SpeciesCode.ToUpper(); List <PointCountBeyond50> beyond50 = entry.GetListBeyond50(); List <PointCountWithin50> within50 = entry.GetListWithin50(); beyond50.FindAll(y => y.Id.Equals(0)).ForEach(x => { ObservationMapper.Update(x); _state.PointSurvey.Observations.Add(x); }); within50.FindAll(y => y.Id.Equals(0)).ForEach(x => { ObservationMapper.Update(x); _state.PointSurvey.Observations.Add(x); }); int deleteBeyond = _state.PointSurvey.Observations.OfType <PointCountBeyond50>().Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Count() - beyond50.Count(); int deleteWithin = _state.PointSurvey.Observations.OfType <PointCountWithin50>().Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Count() - within50.Count(); if (deleteBeyond > 0) { var toDelete = _state.PointSurvey.Observations.Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Take(deleteBeyond); toDelete.ToList().ForEach(x => { ObservationMapper.Delete(x); _state.PointSurvey.Observations.Remove(x); }); } if (deleteWithin > 0) { var toDelete = _state.PointSurvey.Observations.Where(x => x.SpeciesCode.Equals(entry.SpeciesCode)).Take(deleteWithin); toDelete.ToList().ForEach(x => { ObservationMapper.Delete(x); _state.PointSurvey.Observations.Remove(x); }); } }