Quellcode durchsuchen

Removed Id Increment code.

master
George Williams vor 4 Jahren
Ursprung
Commit
a20235c1c3

+ 18
- 18
UnivateProperties_API/Context/DataContext.cs Datei anzeigen

@@ -204,23 +204,23 @@ namespace UnivateProperties_API.Context
204 204
         }
205 205
 
206 206
     
207
-        public int GetMaxID(string tableName)
208
-        {
209
-            NpgsqlConnection connection = new NpgsqlConnection(connectionString);
210
-            connection.Open();
211
-
212
-            NpgsqlCommand cmd = connection.CreateCommand();
213
-            cmd.CommandText = string.Format("select MAX(\"Id\") from \"{0}\"", tableName);
214
-            NpgsqlDataReader reader = cmd.ExecuteReader();
215
-            int returnValue = 0; 
216
-
217
-            while(reader.Read())
218
-            {
219
-                returnValue = int.Parse(reader[0] == null ? "0" : reader[0].ToString() == "" ? "0" : reader[0].ToString());
220
-            }
221
-
222
-            connection.Close();
223
-            return returnValue;
224
-        }
207
+        //public int GetMaxID(string tableName)
208
+        //{
209
+        //    NpgsqlConnection connection = new NpgsqlConnection(connectionString);
210
+        //    connection.Open();
211
+
212
+        //    NpgsqlCommand cmd = connection.CreateCommand();
213
+        //    cmd.CommandText = string.Format("select MAX(\"Id\") from \"{0}\"", tableName);
214
+        //    NpgsqlDataReader reader = cmd.ExecuteReader();
215
+        //    int returnValue = 0; 
216
+
217
+        //    while(reader.Read())
218
+        //    {
219
+        //        returnValue = int.Parse(reader[0] == null ? "0" : reader[0].ToString() == "" ? "0" : reader[0].ToString());
220
+        //    }
221
+
222
+        //    connection.Close();
223
+        //    return returnValue;
224
+        //}
225 225
     }
226 226
 }

+ 10
- 37
UnivateProperties_API/Repository/Campaigns/CampaignRepository.cs Datei anzeigen

@@ -248,37 +248,19 @@ namespace UnivateProperties_API.Repository.Campaigns
248 248
         }
249 249
 
250 250
         public void Insert(Campaign item)
251
-        {
252
-            item.Id = NewId();
253
-
254
-            int last = _dbContext.GetMaxID("CampaignPlaceHolders") + 1;
251
+        {                        
255 252
             if (item.PlaceHolders.Count > 0)
256 253
             {
257 254
                 foreach (var ph in item.PlaceHolders)
258 255
                 {
259 256
                     ph.CampaignId = item.Id;
260
-                    ph.Id = last;
261
-                    last++;
262 257
                 }
263
-            }
264
-
265
-            last = _dbContext.GetMaxID("CampaignItems") + 1;
266
-            int lastCustom = _dbContext.GetMaxID("CampaignItemPlaceHolders") + 1;
258
+            }            
267 259
             if (item.Items.Count > 0)
268 260
             {
269 261
                 foreach (var i in item.Items)
270 262
                 {
271 263
                     i.CampaignId = item.Id;
272
-                    i.Id = last;
273
-                    last++;
274
-                    if (i.CampaignItemPlaceHolder != null)
275
-                    {
276
-                        foreach (var c in i.CampaignItemPlaceHolder)
277
-                        {
278
-                            c.Id = lastCustom;
279
-                            lastCustom++;
280
-                        }
281
-                    }
282 264
                 }
283 265
             }
284 266
 
@@ -298,8 +280,7 @@ namespace UnivateProperties_API.Repository.Campaigns
298 280
         public int InsertFromDTO(CampaignDTO campaign)
299 281
         {
300 282
             var cam = new Campaign
301
-            {
302
-                Id = NewId(),
283
+            {                
303 284
                 Name = campaign.Name,
304 285
                 StartDate = campaign.StartDate,
305 286
                 EndDate = campaign.EndDate,
@@ -308,18 +289,14 @@ namespace UnivateProperties_API.Repository.Campaigns
308 289
                 ItemBody = campaign.ItemBody,
309 290
                 ItemsPerRow = campaign.ItemsPerRow
310 291
             };
311
-
312
-            int lastID = _dbContext.GetMaxID("CampaignPlaceHolders") + 1;
313
-
292
+            
314 293
             if (campaign.PlaceHolders.Count > 0)
315 294
             {
316 295
                 cam.PlaceHolders = new List<CampaignPlaceHolder>();
317 296
                 foreach (var place in campaign.PlaceHolders)
318
-                {
319
-                    lastID++;
297
+                {                    
320 298
                     cam.PlaceHolders.Add(new CampaignPlaceHolder()
321
-                    {
322
-                        Id = lastID,
299
+                    {                        
323 300
                         CampaignId = cam.Id,
324 301
                         Name = place.Name,
325 302
                         BoundTo = place.BoundTo,
@@ -330,16 +307,13 @@ namespace UnivateProperties_API.Repository.Campaigns
330 307
             }
331 308
 
332 309
             if (campaign.Weeks.Count > 0)
333
-            {                
334
-                lastID = _dbContext.GetMaxID("CampaignItems") + 1;
310
+            {                                
335 311
                 cam.Items = new List<CampaignItem>();
336 312
                 foreach (var week in campaign.Weeks)
337
-                {
338
-                    lastID++;
313
+                {                    
339 314
                     cam.Items.Add(new CampaignItem()
340 315
                     {
341 316
                         CampaignId = cam.Id,
342
-                        Id = lastID,
343 317
                         WeekId = week.WeekId,
344 318
                         Image = week.Image
345 319
                     });
@@ -347,8 +321,7 @@ namespace UnivateProperties_API.Repository.Campaigns
347 321
             }
348 322
 
349 323
             if (campaign.WeekPlaceHolders.Count > 0)
350
-            {
351
-                lastID = _dbContext.GetMaxID("CampaignItemPlaceHolders") + 1;                
324
+            {                    
352 325
                 foreach (var wph in campaign.WeekPlaceHolders)
353 326
                 {
354 327
                     var week = cam.Items.Where(w => w.WeekId == wph.WeekId).FirstOrDefault();
@@ -373,7 +346,7 @@ namespace UnivateProperties_API.Repository.Campaigns
373 346
 
374 347
         public int NewId()
375 348
         {
376
-            return _dbContext.GetMaxID("Campaigns") + 1;
349
+            throw new NotImplementedException();
377 350
         }
378 351
 
379 352
         public void Remove(Campaign item)

+ 9
- 21
UnivateProperties_API/Repository/Communication/TemplateRepository.cs Datei anzeigen

@@ -43,28 +43,16 @@ namespace UnivateProperties_API.Repository.Communication
43 43
         }
44 44
 
45 45
         public void Insert(Template item)
46
-        {
47
-            item.Id = NewId();
48
-
49
-            int maxIDPlaceHolder = _dbContext.GetMaxID("PlaceHolders") + 1;
50
-            foreach (var p in item.PlaceHolders)
51
-            {
52
-                p.Id = maxIDPlaceHolder;
53
-                maxIDPlaceHolder++;
54
-            }
55
-
46
+        {                            
56 47
             _dbContext.Add(item);
57 48
             Save();
58 49
         }
59 50
 
60 51
         public void Insert(IEnumerable<Template> items)
61
-        {
62
-            int id = NewId();
52
+        {            
63 53
             foreach (var item in items)
64
-            {
65
-                item.Id = id;
54
+            {                
66 55
                 _dbContext.Add(item);
67
-                id += 1;
68 56
             }
69 57
             Save();
70 58
         }
@@ -123,12 +111,7 @@ namespace UnivateProperties_API.Repository.Communication
123 111
         public void Save()
124 112
         {
125 113
             _dbContext.SaveChanges();
126
-        }
127
-
128
-        public int NewId()
129
-        {            
130
-            return _dbContext.GetMaxID("Templates") + 1;
131
-        }
114
+        }        
132 115
 
133 116
         public List<TemplateDto> GetSimpleAll()
134 117
         {
@@ -193,5 +176,10 @@ namespace UnivateProperties_API.Repository.Communication
193 176
                 }
194 177
             }
195 178
         }
179
+
180
+        public int NewId()
181
+        {
182
+            throw new NotImplementedException();
183
+        }
196 184
     }
197 185
 }

+ 1
- 2
UnivateProperties_API/Repository/Misc/CarouselRepository.cs Datei anzeigen

@@ -58,8 +58,7 @@ namespace UnivateProperties_API.Repository.Misc
58 58
         public void Insert(Carousel item)
59 59
         {
60 60
             string image = item.Image;
61
-            item.Image = "";
62
-            item.Id = dBContext.GetMaxID("Carousel") + 1;
61
+            item.Image = "";            
63 62
             dBContext.Add(item);
64 63
             Save();
65 64
 

+ 1
- 2
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs Datei anzeigen

@@ -194,8 +194,7 @@ namespace UnivateProperties_API.Repository.ProccessFlow
194 194
             {
195 195
                 if (prop != "Item" && prop != "Display")
196 196
                     bid[prop] = item[prop];
197
-            }
198
-            bid.Id = _dbContext.GetMaxID("BidItems") + 1;
197
+            }            
199 198
 
200 199
             var status = _dbContext.Status.Where(x => x.Code == "E1").FirstOrDefault();
201 200
             if (status != null)            

+ 6
- 7
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Datei anzeigen

@@ -125,9 +125,7 @@ namespace UnivateProperties_API.Repository.Properties
125 125
         public void Update(NewPropertyImages propertyImages)
126 126
         {
127 127
             if (propertyImages.Images != null)
128
-            {
129
-                var lastID = dBContext.GetMaxID("PropertyImages");
130
-
128
+            {                
131 129
                 bool saveFiles = false;
132 130
                 var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
133 131
                 if (!string.IsNullOrEmpty(loc))
@@ -140,18 +138,19 @@ namespace UnivateProperties_API.Repository.Properties
140 138
                     }
141 139
                 }
142 140
 
141
+                var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
142
+
143 143
                 foreach (var image in propertyImages.Images)
144
-                {
145
-                    lastID++;
144
+                {                   
146 145
                     var newImage = new PropertyImage
147
-                    {
148
-                        Id = lastID,
146
+                    {                        
149 147
                         PropertyId = propertyImages.PropertyId
150 148
                     };
151 149
                     if (saveFiles)
152 150
                     {
153 151
                         string path = ImageFormatter.Base64ToImage(image.Image, loc, lastID.ToString());
154 152
                         newImage.Image = path;
153
+                        lastID++;
155 154
                     }
156 155
                     else
157 156
                     {

+ 12
- 27
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Datei anzeigen

@@ -225,18 +225,14 @@ namespace UnivateProperties_API.Repository.Properties
225 225
 
226 226
             #region Insert New UDFs
227 227
 
228
-            var lastFieldID = dBContext.GetMaxID("PropertyUserFields");
229
-
230 228
             foreach (var propGroup in item.PropertyOverviewFields)
231 229
             {
232 230
                 foreach (var field in propGroup.Fields)
233 231
                 {
234 232
                     if (field.ItemId == 0)
235
-                    {
236
-                        lastFieldID++;
233
+                    {                        
237 234
                         var propertyField = new PropertyUserField()
238
-                        {
239
-                            Id = lastFieldID,
235
+                        {                            
240 236
                             PropertyId = property.Id,
241 237
                             UserDefinedFieldId = field.Id,
242 238
                             Value = field.Value
@@ -264,11 +260,9 @@ namespace UnivateProperties_API.Repository.Properties
264 260
                 foreach (var field in propGroup.Fields)
265 261
                 {
266 262
                     if (field.ItemId == 0)
267
-                    {
268
-                        lastFieldID++;
263
+                    {                        
269 264
                         var propertyField = new PropertyUserField()
270
-                        {
271
-                            Id = lastFieldID,
265
+                        {                            
272 266
                             PropertyId = property.Id,
273 267
                             UserDefinedFieldId = field.Id,
274 268
                             Value = field.Value
@@ -496,8 +490,7 @@ namespace UnivateProperties_API.Repository.Properties
496 490
             {
497 491
                 Type = item.Type,
498 492
                 Search = JsonConvert.SerializeObject(item)
499
-            };
500
-            searchLog.Id = dBContext.GetMaxID("SearchLogs") + 1;
493
+            };            
501 494
             dBContext.SearchLogs.Add(searchLog);
502 495
             Save();
503 496
         }
@@ -727,9 +720,7 @@ namespace UnivateProperties_API.Repository.Properties
727 720
             {
728 721
                 property.AgencyId = agent.AgencyId;
729 722
                 property.AgentId = agent.Id;
730
-            }
731
-
732
-            property.Id = dBContext.GetMaxID("Properties") + 1;
723
+            }            
733 724
 
734 725
             if (status != null)
735 726
                 property.StatusId = status.Id;
@@ -738,8 +729,6 @@ namespace UnivateProperties_API.Repository.Properties
738 729
 
739 730
             if (images != null)
740 731
             {
741
-                var lastID = dBContext.GetMaxID("PropertyImages");
742
-
743 732
                 bool saveFiles = false;
744 733
                 var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
745 734
                 if (!string.IsNullOrEmpty(loc))
@@ -753,10 +742,9 @@ namespace UnivateProperties_API.Repository.Properties
753 742
                 }
754 743
 
755 744
                 property.PropertyImages = new List<PropertyImage>();
745
+                var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
756 746
                 foreach (PropertyImage image in images)
757 747
                 {
758
-                    lastID++;
759
-                    image.Id = lastID;
760 748
                     image.PropertyId = property.Id;
761 749
                     if (saveFiles)
762 750
                     {
@@ -764,17 +752,15 @@ namespace UnivateProperties_API.Repository.Properties
764 752
                         image.Image = path;
765 753
                     }
766 754
                     property.PropertyImages.Add(image);
755
+                    lastID++;
767 756
                 }
768 757
             }
769 758
 
770 759
             if (fields != null)
771
-            {
772
-                var lastID = dBContext.GetMaxID("PropertyUserFields");
760
+            {                
773 761
                 property.PropertyUserFields = new List<PropertyUserField>();
774 762
                 foreach (PropertyUserField field in fields)
775 763
                 {
776
-                    lastID++;
777
-                    field.Id = lastID;
778 764
                     field.PropertyId = property.Id;
779 765
                     property.PropertyUserFields.Add(field);
780 766
                 }
@@ -800,7 +786,7 @@ namespace UnivateProperties_API.Repository.Properties
800 786
         {
801 787
             if (Images != null)
802 788
             {
803
-                var lastID = dBContext.GetMaxID("PropertyImages");
789
+                var lastID = dBContext.PropertyImages.Max(i => i.Id) + 1;
804 790
 
805 791
                 bool saveFiles = false;
806 792
                 var loc = dBContext.Location.FirstOrDefault()?.PropertyImageLocation;
@@ -815,9 +801,7 @@ namespace UnivateProperties_API.Repository.Properties
815 801
                 }
816 802
 
817 803
                 foreach (PropertyImage image in Images)
818
-                {
819
-                    lastID++;
820
-                    image.Id = lastID;
804
+                {                                    
821 805
                     image.PropertyId = propertyID;
822 806
                     if (saveFiles)
823 807
                     {
@@ -825,6 +809,7 @@ namespace UnivateProperties_API.Repository.Properties
825 809
                         image.Image = path;
826 810
                     }
827 811
                     dBContext.PropertyImages.Add(image);
812
+                    lastID++;
828 813
                     Save();
829 814
                 }
830 815
             }

Laden…
Abbrechen
Speichern