Explorar el Código

Removed Id Increment code.

master
George Williams hace 4 años
padre
commit
a20235c1c3

+ 18
- 18
UnivateProperties_API/Context/DataContext.cs Ver fichero

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 Ver fichero

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

+ 9
- 21
UnivateProperties_API/Repository/Communication/TemplateRepository.cs Ver fichero

43
         }
43
         }
44
 
44
 
45
         public void Insert(Template item)
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
             _dbContext.Add(item);
47
             _dbContext.Add(item);
57
             Save();
48
             Save();
58
         }
49
         }
59
 
50
 
60
         public void Insert(IEnumerable<Template> items)
51
         public void Insert(IEnumerable<Template> items)
61
-        {
62
-            int id = NewId();
52
+        {            
63
             foreach (var item in items)
53
             foreach (var item in items)
64
-            {
65
-                item.Id = id;
54
+            {                
66
                 _dbContext.Add(item);
55
                 _dbContext.Add(item);
67
-                id += 1;
68
             }
56
             }
69
             Save();
57
             Save();
70
         }
58
         }
123
         public void Save()
111
         public void Save()
124
         {
112
         {
125
             _dbContext.SaveChanges();
113
             _dbContext.SaveChanges();
126
-        }
127
-
128
-        public int NewId()
129
-        {            
130
-            return _dbContext.GetMaxID("Templates") + 1;
131
-        }
114
+        }        
132
 
115
 
133
         public List<TemplateDto> GetSimpleAll()
116
         public List<TemplateDto> GetSimpleAll()
134
         {
117
         {
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 Ver fichero

58
         public void Insert(Carousel item)
58
         public void Insert(Carousel item)
59
         {
59
         {
60
             string image = item.Image;
60
             string image = item.Image;
61
-            item.Image = "";
62
-            item.Id = dBContext.GetMaxID("Carousel") + 1;
61
+            item.Image = "";            
63
             dBContext.Add(item);
62
             dBContext.Add(item);
64
             Save();
63
             Save();
65
 
64
 

+ 1
- 2
UnivateProperties_API/Repository/ProccessFlow/BidRepository.cs Ver fichero

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

+ 6
- 7
UnivateProperties_API/Repository/Properties/PropertyImageRepository.cs Ver fichero

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

+ 12
- 27
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Ver fichero

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

Loading…
Cancelar
Guardar