source: Application/Dal/ApplicationStorage/ApiContext.cs

Last change on this file was f5f7c24, checked in by 192011 <mk.snicker@…>, 17 months ago

Initial commit

  • Property mode set to 100644
File size: 16.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using Microsoft.EntityFrameworkCore;
4using Microsoft.Extensions.Configuration;
5using Models.DatabaseModels;
6using ocrent;
7
8namespace Dal.ApplicationStorage;
9
10public partial class ApiContext : DbContext
11{
12 IConfiguration configuration;
13 public ApiContext(DbContextOptions<ApiContext> options, IConfiguration configuration)
14 : base(options)
15 {
16 this.configuration = configuration;
17 }
18
19 public virtual DbSet<Administrator> Administrators { get; set; }
20
21 public virtual DbSet<BusinessUser> BusinessUsers { get; set; }
22
23 public virtual DbSet<Client> Clients { get; set; }
24
25 public virtual DbSet<Company> Companies { get; set; }
26
27 public virtual DbSet<Contract> Contracts { get; set; }
28
29 public virtual DbSet<DeliveryMan> DeliveryMen { get; set; }
30
31 public virtual DbSet<Location> Locations { get; set; }
32
33 public virtual DbSet<Model> Models { get; set; }
34
35 public virtual DbSet<Payment> Payments { get; set; }
36
37 public virtual DbSet<PaymentCard> PaymentCards { get; set; }
38
39 public virtual DbSet<Registration> Registrations { get; set; }
40
41 public virtual DbSet<User> Users { get; set; }
42
43 public virtual DbSet<Vehicle> Vehicles { get; set; }
44
45 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
46 => optionsBuilder.UseNpgsql(configuration.GetConnectionString("ApiDatabase"));
47
48 protected override void OnModelCreating(ModelBuilder modelBuilder)
49 {
50 modelBuilder.Entity<Administrator>(entity =>
51 {
52 entity.HasKey(e => e.UserId).HasName("administrators_pkey");
53
54 entity.ToTable("administrators", "project");
55
56 entity.Property(e => e.UserId)
57 .ValueGeneratedNever()
58 .HasColumnName("user_id");
59
60 entity.HasOne(d => d.User).WithOne(p => p.Administrator)
61 .HasForeignKey<Administrator>(d => d.UserId)
62 .HasConstraintName("administrators_user_id_fkey");
63 });
64
65 modelBuilder.Entity<BusinessUser>(entity =>
66 {
67 entity.HasKey(e => e.UserId).HasName("business_users_pkey");
68
69 entity.ToTable("business_users", "project");
70
71 entity.Property(e => e.UserId)
72 .ValueGeneratedNever()
73 .HasColumnName("user_id");
74
75 entity.HasOne(d => d.User).WithOne(p => p.BusinessUser)
76 .HasForeignKey<BusinessUser>(d => d.UserId)
77 .HasConstraintName("business_users_user_id_fkey");
78 });
79
80 modelBuilder.Entity<Client>(entity =>
81 {
82 entity.HasKey(e => e.UserId).HasName("clients_pkey");
83
84 entity.ToTable("clients", "project");
85
86 entity.Property(e => e.UserId)
87 .ValueGeneratedNever()
88 .HasColumnName("user_id");
89
90 entity.HasOne(d => d.User).WithOne(p => p.Client)
91 .HasForeignKey<Client>(d => d.UserId)
92 .HasConstraintName("clients_user_id_fkey");
93 });
94
95 modelBuilder.Entity<Company>(entity =>
96 {
97 entity.HasKey(e => e.CompanyId).HasName("companies_pkey");
98
99 entity.ToTable("companies", "project");
100
101 entity.Property(e => e.CompanyId).HasColumnName("company_id");
102 entity.Property(e => e.AdministratorId).HasColumnName("administrator_id");
103 entity.Property(e => e.BusinessUserId).HasColumnName("business_user_id");
104 entity.Property(e => e.CompanyEmail)
105 .HasMaxLength(256)
106 .HasColumnName("company_email");
107 entity.Property(e => e.CompanyName)
108 .HasMaxLength(256)
109 .HasColumnName("company_name");
110 entity.Property(e => e.CreatedBy).HasColumnName("created_by");
111 entity.Property(e => e.CreatedOn).HasColumnName("created_on");
112 entity.Property(e => e.ModifiedBy).HasColumnName("modified_by");
113 entity.Property(e => e.ModifiedOn).HasColumnName("modified_on");
114
115 entity.HasOne(d => d.Administrator).WithMany(p => p.Companies)
116 .HasForeignKey(d => d.AdministratorId)
117 .OnDelete(DeleteBehavior.Cascade)
118 .HasConstraintName("companies_administrator_id_fkey");
119
120 entity.HasOne(d => d.BusinessUser).WithMany(p => p.Companies)
121 .HasForeignKey(d => d.BusinessUserId)
122 .OnDelete(DeleteBehavior.Cascade)
123 .HasConstraintName("companies_business_user_id_fkey");
124 });
125
126 modelBuilder.Entity<Contract>(entity =>
127 {
128 entity.HasKey(e => new { e.SignedDate, e.UserId, e.VehicleId, e.DeliveryManId }).HasName("pk_contract");
129
130 entity.ToTable("contracts", "project");
131
132 entity.Property(e => e.SignedDate).HasColumnName("signed_date");
133 entity.Property(e => e.UserId).HasColumnName("user_id");
134 entity.Property(e => e.VehicleId).HasColumnName("vehicle_id");
135 entity.Property(e => e.DeliveryManId).HasColumnName("delivery_man_id");
136 entity.Property(e => e.Address)
137 .HasMaxLength(50)
138 .HasColumnName("address");
139 entity.Property(e => e.CardId).HasColumnName("card_id");
140 entity.Property(e => e.EndDate).HasColumnName("end_date");
141 entity.Property(e => e.Hasbabyseat)
142 .HasDefaultValueSql("false")
143 .HasColumnName("hasbabyseat");
144 entity.Property(e => e.Hasgreencard)
145 .HasDefaultValueSql("false")
146 .HasColumnName("hasgreencard");
147 entity.Property(e => e.Hasnavigation)
148 .HasDefaultValueSql("false")
149 .HasColumnName("hasnavigation");
150 entity.Property(e => e.Hasroofrack)
151 .HasDefaultValueSql("false")
152 .HasColumnName("hasroofrack");
153 entity.Property(e => e.PaymentId).HasColumnName("payment_id");
154 entity.Property(e => e.Review)
155 .HasMaxLength(500)
156 .HasColumnName("review");
157 entity.Property(e => e.StartDate).HasColumnName("start_date");
158
159 entity.HasOne(d => d.DeliveryMan).WithMany(p => p.Contracts)
160 .HasForeignKey(d => d.DeliveryManId)
161 .HasConstraintName("contracts_delivery_man_id_fkey");
162
163 entity.HasOne(d => d.User).WithMany(p => p.Contracts)
164 .HasForeignKey(d => d.UserId)
165 .HasConstraintName("contracts_user_id_fkey");
166
167 entity.HasOne(d => d.Vehicle).WithMany(p => p.Contracts)
168 .HasForeignKey(d => d.VehicleId)
169 .HasConstraintName("contracts_vehicle_id_fkey");
170
171 entity.HasOne(d => d.Payment).WithMany(p => p.Contracts)
172 .HasForeignKey(d => new { d.PaymentId, d.CardId })
173 .OnDelete(DeleteBehavior.Cascade)
174 .HasConstraintName("fk_contract_payment");
175 });
176
177 modelBuilder.Entity<DeliveryMan>(entity =>
178 {
179 entity.HasKey(e => e.UserId).HasName("delivery_man_pkey");
180
181 entity.ToTable("delivery_man", "project");
182
183 entity.Property(e => e.UserId)
184 .ValueGeneratedNever()
185 .HasColumnName("user_id");
186 entity.Property(e => e.BusinessUserId).HasColumnName("business_user_id");
187 entity.Property(e => e.CompanyId).HasColumnName("company_id");
188 entity.Property(e => e.DateOfEmployment).HasColumnName("date_of_employment");
189 entity.Property(e => e.Salary).HasColumnName("salary");
190
191 entity.HasOne(d => d.BusinessUser).WithMany(p => p.DeliveryManBusinessUsers)
192 .HasForeignKey(d => d.BusinessUserId)
193 .OnDelete(DeleteBehavior.Cascade)
194 .HasConstraintName("delivery_man_business_user_id_fkey");
195
196 entity.HasOne(d => d.Company).WithMany(p => p.DeliveryMen)
197 .HasForeignKey(d => d.CompanyId)
198 .OnDelete(DeleteBehavior.Cascade)
199 .HasConstraintName("delivery_man_company_id_fkey");
200
201 entity.HasOne(d => d.User).WithOne(p => p.DeliveryManUser)
202 .HasForeignKey<DeliveryMan>(d => d.UserId)
203 .HasConstraintName("delivery_man_user_id_fkey");
204
205 entity.HasMany(d => d.Vehicles).WithMany(p => p.Users)
206 .UsingEntity<Dictionary<string, object>>(
207 "IsResponsibleFor",
208 r => r.HasOne<Vehicle>().WithMany()
209 .HasForeignKey("VehicleId")
210 .HasConstraintName("is_responsible_for_vehicle_id_fkey"),
211 l => l.HasOne<DeliveryMan>().WithMany()
212 .HasForeignKey("UserId")
213 .HasConstraintName("is_responsible_for_user_id_fkey"),
214 j =>
215 {
216 j.HasKey("UserId", "VehicleId").HasName("pk_is_responsible_for");
217 j.ToTable("is_responsible_for", "project");
218 });
219 });
220
221 modelBuilder.Entity<Location>(entity =>
222 {
223 entity.HasKey(e => new { e.LocationId, e.CompanyId }).HasName("pk_locations");
224
225 entity.ToTable("locations", "project");
226
227 entity.Property(e => e.LocationId)
228 .ValueGeneratedOnAdd()
229 .HasColumnName("location_id");
230 entity.Property(e => e.CompanyId).HasColumnName("company_id");
231 entity.Property(e => e.City)
232 .HasMaxLength(50)
233 .HasColumnName("city");
234 entity.Property(e => e.Street)
235 .HasMaxLength(100)
236 .HasColumnName("street");
237 entity.Property(e => e.StreetNumber).HasColumnName("street_number");
238
239 entity.HasOne(d => d.Company).WithMany(p => p.Locations)
240 .HasForeignKey(d => d.CompanyId)
241 .HasConstraintName("locations_company_id_fkey");
242 });
243
244 modelBuilder.Entity<Model>(entity =>
245 {
246 entity.HasKey(e => e.ModelId).HasName("models_pkey");
247
248 entity.ToTable("models", "project");
249
250 entity.Property(e => e.ModelId).HasColumnName("model_id");
251 entity.Property(e => e.Color)
252 .HasMaxLength(30)
253 .HasColumnName("color");
254 entity.Property(e => e.Fuel)
255 .HasMaxLength(30)
256 .HasColumnName("fuel");
257 entity.Property(e => e.ModelName)
258 .HasMaxLength(100)
259 .HasColumnName("model_name");
260 entity.Property(e => e.ModelYear).HasColumnName("model_year");
261 entity.Property(e => e.NumOfDoors).HasColumnName("num_of_doors");
262 entity.Property(e => e.NumOfSeats).HasColumnName("num_of_seats");
263 entity.Property(e => e.Transmission)
264 .HasMaxLength(10)
265 .HasColumnName("transmission");
266 entity.Property(e => e.VehicleType)
267 .HasMaxLength(30)
268 .HasColumnName("vehicle_type");
269 entity.Property(e => e.ImgUrl).HasColumnName("img_url");
270 });
271
272 modelBuilder.Entity<Payment>(entity =>
273 {
274 entity.HasKey(e => new { e.PaymentId, e.CardId }).HasName("pk_payment");
275
276 entity.ToTable("payments", "project");
277
278 entity.HasIndex(e => e.PaymentId, "payments_payment_id_key").IsUnique();
279
280 entity.Property(e => e.PaymentId)
281 .ValueGeneratedOnAdd()
282 .HasColumnName("payment_id");
283 entity.Property(e => e.CardId).HasColumnName("card_id");
284 entity.Property(e => e.Amount).HasColumnName("amount");
285 entity.Property(e => e.PaymentDate).HasColumnName("payment_date");
286 entity.Property(e => e.PaymentTime).HasColumnName("payment_time");
287
288 entity.HasOne(d => d.Card).WithMany(p => p.Payments)
289 .HasForeignKey(d => d.CardId)
290 .HasConstraintName("payments_card_id_fkey");
291 });
292
293 modelBuilder.Entity<PaymentCard>(entity =>
294 {
295 entity.HasKey(e => e.CardId).HasName("payment_cards_pkey");
296
297 entity.ToTable("payment_cards", "project");
298
299 entity.Property(e => e.CardId).HasColumnName("card_id");
300 entity.Property(e => e.CardNumber)
301 .HasMaxLength(16)
302 .HasColumnName("card_number");
303 entity.Property(e => e.Cvc).HasColumnName("cvc");
304 entity.Property(e => e.HolderName)
305 .HasMaxLength(100)
306 .HasColumnName("holder_name");
307 entity.Property(e => e.UserId).HasColumnName("user_id");
308 entity.Property(e => e.ValidThru).HasColumnName("valid_thru");
309
310 entity.HasOne(d => d.User).WithMany(p => p.PaymentCards)
311 .HasForeignKey(d => d.UserId)
312 .OnDelete(DeleteBehavior.Cascade)
313 .HasConstraintName("payment_cards_user_id_fkey");
314 });
315
316 modelBuilder.Entity<Registration>(entity =>
317 {
318 entity.HasKey(e => e.RegistrationId).HasName("registrations_pkey");
319
320 entity.ToTable("registrations", "project");
321
322 entity.Property(e => e.RegistrationId).HasColumnName("registration_id");
323 entity.Property(e => e.IsAvailable).HasColumnName("is_available");
324 entity.Property(e => e.PlateNum)
325 .HasMaxLength(8)
326 .HasColumnName("plate_num");
327 entity.Property(e => e.RegistredOn).HasColumnName("registred_on");
328 entity.Property(e => e.ValidThru).HasColumnName("valid_thru");
329 });
330
331 modelBuilder.Entity<User>(entity =>
332 {
333 entity.HasKey(e => e.UserId).HasName("users_pkey");
334
335 entity.ToTable("users", "project");
336
337 entity.HasIndex(e => e.Email, "users_email_key").IsUnique();
338
339 entity.HasIndex(e => e.Username, "users_username_key").IsUnique();
340
341 entity.Property(e => e.UserId).HasColumnName("user_id");
342 entity.Property(e => e.CreatedOn).HasColumnName("created_on");
343 entity.Property(e => e.Email)
344 .HasMaxLength(255)
345 .HasColumnName("email");
346 entity.Property(e => e.FirstName)
347 .HasMaxLength(255)
348 .HasColumnName("first_name");
349 entity.Property(e => e.LastName)
350 .HasMaxLength(255)
351 .HasColumnName("last_name");
352 entity.Property(e => e.ModifiedOn).HasColumnName("modified_on");
353 entity.Property(e => e.Pass)
354 .HasMaxLength(255)
355 .HasColumnName("pass");
356 entity.Property(e => e.Username)
357 .HasMaxLength(255)
358 .HasColumnName("username");
359 });
360
361 modelBuilder.Entity<Vehicle>(entity =>
362 {
363 entity.HasKey(e => e.VehicleId).HasName("vehicles_pkey");
364
365 entity.ToTable("vehicles", "project");
366
367 entity.Property(e => e.VehicleId).HasColumnName("vehicle_id");
368 entity.Property(e => e.Brand)
369 .HasMaxLength(50)
370 .HasColumnName("brand");
371 entity.Property(e => e.ChassisNumber)
372 .HasMaxLength(17)
373 .HasColumnName("chassis_number");
374 entity.Property(e => e.CompanyId).HasColumnName("company_id");
375 entity.Property(e => e.DailyRentalPrice).HasColumnName("daily_rental_price");
376 entity.Property(e => e.FuelEfficiency)
377 .HasMaxLength(15)
378 .HasColumnName("fuel_efficiency");
379 entity.Property(e => e.LocationId).HasColumnName("location_id");
380 entity.Property(e => e.ModelId).HasColumnName("model_id");
381 entity.Property(e => e.RegistrationId).HasColumnName("registration_id");
382 entity.Property(e => e.VehicleType)
383 .HasMaxLength(30)
384 .HasColumnName("vehicle_type");
385
386 entity.HasOne(d => d.Model).WithMany(p => p.Vehicles)
387 .HasForeignKey(d => d.ModelId)
388 .OnDelete(DeleteBehavior.Cascade)
389 .HasConstraintName("vehicles_model_id_fkey");
390
391 entity.HasOne(d => d.Registration).WithMany(p => p.Vehicles)
392 .HasForeignKey(d => d.RegistrationId)
393 .OnDelete(DeleteBehavior.Cascade)
394 .HasConstraintName("vehicles_registration_id_fkey");
395
396 entity.HasOne(d => d.Location).WithMany(p => p.Vehicles)
397 .HasForeignKey(d => new { d.LocationId, d.CompanyId })
398 .OnDelete(DeleteBehavior.Cascade)
399 .HasConstraintName("fk_location");
400 });
401
402 OnModelCreatingPartial(modelBuilder);
403 }
404
405 partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
406}
Note: See TracBrowser for help on using the repository browser.