private static bool UpdateH2HRecord(ref House2HouseRecordData rec)
        {
            if (rec.ItemId < 0)
            {
                return(AddH2HRecord(ref rec));
            }
            try {
                using (var db = new House2HouseRecordDataContext()) {
                    int itemId = rec.ItemId;
                    var rec2   = db.House2HouseRecordItems.Single(s => s.ItemId == itemId);

                    rec2.Date                 = rec.Date;
                    rec2.HouseAptNumber       = rec.HouseAptNumber;
                    rec2.NamePlacementRemarks = rec.NamePlacementRemarks;
                    rec2.StreetItemId         = rec.StreetItemId;
                    rec2.Symbol               = rec.Symbol;
                    rec2.TerritoryItemId      = rec.TerritoryItemId;

                    db.SubmitChanges();

                    return(true);
                }
            } catch (InvalidOperationException) {
                return(AddH2HRecord(ref rec)); //rv not found, lets create it`
            }
        }
 private static bool AddH2HRecord(ref House2HouseRecordData rec)
 {
     using (var db = new House2HouseRecordDataContext()) {
         var r   = House2HouseRecordData.Copy(rec);
         var qry = from x in db.House2HouseRecordItems
                   //unique items
                   where x.HouseAptNumber.Equals(r.HouseAptNumber) &&
                   x.StreetItemId.Equals(r.StreetItemId) &&
                   x.TerritoryItemId.Equals(r.TerritoryItemId)
                   select x;
         if (qry.Any())
         {
             throw new H2HRecordAlreadyExistsException();
         }
         db.House2HouseRecordItems.InsertOnSubmit(r);
         db.SubmitChanges();
         rec.ItemId = r.ItemId;
         return(rec.ItemId >= 0);
     }
 }