コード例 #1
0
 internal static StreetsBuildingItem Copy(StreetBuildingData item)
 {
     return(new StreetsBuildingItem()
     {
         ItemId = item.ItemId,
         BuildingNumber = item.BuildingNumber,
         DateCreated = item.DateCreated,
         Street = item.Street,
         TerritoyrCardId = item.TerritoryCardId
     });
 }
コード例 #2
0
 public static StreetBuildingData GetStreetBuilding(int itemId)
 {
     using (var db = new StreetsBuildingDataContext()) {
         try {
             var s = db.StreetsBuildingItems.Single(r => r.ItemId == itemId);
             return(StreetBuildingData.Copy(s));
         } catch (InvalidOperationException) {
             throw new StreetBuildingItemDoesntExistException();
         }
     }
 }
コード例 #3
0
 public static bool AddOrUpdate(ref StreetBuildingData st)
 {
     try {
         if (st.ItemId < 0)
         {
             return(AddNewStreetBuilding(ref st));
         }
         return(UpdateStreetBuilding(ref st));
     } catch (StreetBuildingItemDoesntExistException) {
         return(UpdateStreetBuilding(ref st));
     } catch (StreetBuildingAlreadyExistsException) {
         return(AddNewStreetBuilding(ref st));
     }
 }
コード例 #4
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();
                }
            }
        }
コード例 #5
0
 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);
     }
 }
コード例 #6
0
 internal static StreetsBuildingItem Copy(StreetBuildingData item)
 {
     return new StreetsBuildingItem() {
         ItemId = item.ItemId,
         BuildingNumber = item.BuildingNumber,
         DateCreated = item.DateCreated,
         Street = item.Street,
         TerritoyrCardId = item.TerritoryCardId
     };
 }
コード例 #7
0
 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;
     }
 }
コード例 #8
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();
                }
            }
        }
コード例 #9
0
        public static bool AddOrUpdate(ref StreetBuildingData st)
        {
            try {
                if (st.ItemId < 0) return AddNewStreetBuilding(ref st);
                return UpdateStreetBuilding(ref st);
            } catch (StreetBuildingItemDoesntExistException) {
                return UpdateStreetBuilding(ref st);
            } catch (StreetBuildingAlreadyExistsException) {
                return AddNewStreetBuilding(ref st);
            }

        }