private static bool AddNewStreetBuilding(ref StreetBuildingData st)
 {
     using (var db = new StreetsBuildingDataContext()) {
         var s = StreetBuildingData.Copy(st);
         var q = from x in db.StreetsBuildingItems
                 where x.TerritoyrCardId.Equals(s.TerritoyrCardId) &&
                       x.Street.Equals(s.Street) &&
                       x.BuildingNumber.Equals(s.BuildingNumber)
                 select x;
         if (q.Any())
             throw new StreetBuildingAlreadyExistsException();
         db.StreetsBuildingItems.InsertOnSubmit(s);
         db.SubmitChanges();
         st.ItemId = s.ItemId;
         return st.ItemId >= 0;
     }
 }
        private static bool UpdateStreetBuilding(ref StreetBuildingData st)
        {
            using (var db = new StreetsBuildingDataContext()) {
                try {
                    var i = st.ItemId;
                    var stEx = db.StreetsBuildingItems.Single(s => s.ItemId == i);
                    stEx.BuildingNumber = st.BuildingNumber;
                    stEx.DateCreated = st.DateCreated;
                    stEx.Street = st.Street;
                    stEx.TerritoyrCardId = st.TerritoryCardId;

                    db.SubmitChanges();
                    return true;
                } catch (InvalidOperationException) {
                    throw new StreetBuildingItemDoesntExistException();
                }
            }
        }