Kaynağa Gözat

Duplicate PK fix

master
George Williams 5 yıl önce
ebeveyn
işleme
4cb566e9d5

+ 6
- 0
UnivateProperties_API/Repository/Properties/PropertyRepository.cs Dosyayı Görüntüle

@@ -155,8 +155,14 @@ namespace UnivateProperties_API.Repository.Properties
155 155
 
156 156
             if (images != null)
157 157
             {
158
+                var lastID = (from p in dBContext.PropertyImages
159
+                              orderby p.Id descending
160
+                              select p.Id).FirstOrDefault();
161
+
158 162
                 foreach (PropertyImage image in images)
159 163
                 {
164
+                    lastID++;
165
+                    image.Id = lastID;
160 166
                     image.PropertyId = item.Id;
161 167
                     dBContext.PropertyImages.Add(image);
162 168
                     Save();

+ 6
- 1
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs Dosyayı Görüntüle

@@ -90,6 +90,11 @@ namespace UnivateProperties_API.Repository.Timeshare
90 90
         public void Insert(TimeshareWeek item)
91 91
         {
92 92
             item = GetDetailedWeek(item);
93
+            item.Id = _dbContext.Weeks.Max(x => x.Id) + 1;
94
+            if (item.Owner != null && item.Owner.Id == 0)
95
+            {
96
+                item.Owner.Id = _dbContext.Individuals.Max(x => x.Id) + 1;
97
+            }
93 98
             // Set starting Status of A1
94 99
             StatusRepository repo = new StatusRepository(_dbContext);
95 100
             item.Status = repo.GetDetailed(s => s.Code == "A1");
@@ -104,7 +109,7 @@ namespace UnivateProperties_API.Repository.Timeshare
104 109
                     ModifiedBy = "KobusB"
105 110
                 };
106 111
             }            
107
-            _dbContext.Add(item);
112
+            _dbContext.Add(item);           
108 113
             Save();
109 114
         }
110 115
 

Loading…
İptal
Kaydet