Browse Source

Duplicate PK fix

master
George Williams 5 years ago
parent
commit
4cb566e9d5

+ 6
- 0
UnivateProperties_API/Repository/Properties/PropertyRepository.cs View File

155
 
155
 
156
             if (images != null)
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
                 foreach (PropertyImage image in images)
162
                 foreach (PropertyImage image in images)
159
                 {
163
                 {
164
+                    lastID++;
165
+                    image.Id = lastID;
160
                     image.PropertyId = item.Id;
166
                     image.PropertyId = item.Id;
161
                     dBContext.PropertyImages.Add(image);
167
                     dBContext.PropertyImages.Add(image);
162
                     Save();
168
                     Save();

+ 6
- 1
UnivateProperties_API/Repository/Timeshare/WeekRepository.cs View File

90
         public void Insert(TimeshareWeek item)
90
         public void Insert(TimeshareWeek item)
91
         {
91
         {
92
             item = GetDetailedWeek(item);
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
             // Set starting Status of A1
98
             // Set starting Status of A1
94
             StatusRepository repo = new StatusRepository(_dbContext);
99
             StatusRepository repo = new StatusRepository(_dbContext);
95
             item.Status = repo.GetDetailed(s => s.Code == "A1");
100
             item.Status = repo.GetDetailed(s => s.Code == "A1");
104
                     ModifiedBy = "KobusB"
109
                     ModifiedBy = "KobusB"
105
                 };
110
                 };
106
             }            
111
             }            
107
-            _dbContext.Add(item);
112
+            _dbContext.Add(item);           
108
             Save();
113
             Save();
109
         }
114
         }
110
 
115
 

Loading…
Cancel
Save