repository migration

This commit is contained in:
2025-05-20 11:46:50 -04:00
commit bf536b8774
213 changed files with 117679 additions and 0 deletions
@@ -0,0 +1,171 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WhiteLagoon.Domain.Entities;
namespace WhiteLagoon.Infrastructure.Data
{
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
public DbSet<Villa> Villas { get; set; }
public DbSet<VillaNumber> VillaNumbers { get; set; }
public DbSet<Amenity> Amenities { get; set; }
public DbSet<ApplicationUser> ApplicationUsers { get; set; }
public DbSet<Booking> Bookings { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Villa>().HasData(
new Villa
{
Id = 1,
Name = "Royal Villa",
Description = "Fusce 11 tincidunt maximus leo, sed scelerisque massa auctor sit amet. Donec ex mauris, hendrerit quis nibh ac, efficitur fringilla enim.",
ImageUrl = "https://placehold.co/600x400",
Occupancy = 4,
Price = 200,
Sqft = 550,
},
new Villa
{
Id = 2,
Name = "Premium Pool Villa",
Description = "Fusce 11 tincidunt maximus leo, sed scelerisque massa auctor sit amet. Donec ex mauris, hendrerit quis nibh ac, efficitur fringilla enim.",
ImageUrl = "https://placehold.co/600x401",
Occupancy = 4,
Price = 300,
Sqft = 550,
},
new Villa
{
Id = 3,
Name = "Luxury Pool Villa",
Description = "Fusce 11 tincidunt maximus leo, sed scelerisque massa auctor sit amet. Donec ex mauris, hendrerit quis nibh ac, efficitur fringilla enim.",
ImageUrl = "https://placehold.co/600x402",
Occupancy = 4,
Price = 400,
Sqft = 750,
});
modelBuilder.Entity<VillaNumber>().HasData(
new VillaNumber
{
Villa_Number = 101,
VillaId = 1,
},
new VillaNumber
{
Villa_Number = 102,
VillaId = 1,
},
new VillaNumber
{
Villa_Number = 103,
VillaId = 1,
},
new VillaNumber
{
Villa_Number = 104,
VillaId = 1,
},
new VillaNumber
{
Villa_Number = 201,
VillaId = 2,
},
new VillaNumber
{
Villa_Number = 202,
VillaId = 2,
},
new VillaNumber
{
Villa_Number = 203,
VillaId = 2,
},
new VillaNumber
{
Villa_Number = 301,
VillaId = 3,
},
new VillaNumber
{
Villa_Number = 302,
VillaId = 3,
}
);
modelBuilder.Entity<Amenity>().HasData(
new Amenity
{
Id = 1,
VillaId = 1,
Name = "Private Pool"
}, new Amenity
{
Id = 2,
VillaId = 1,
Name = "Microwave"
}, new Amenity
{
Id = 3,
VillaId = 1,
Name = "Private Balcony"
}, new Amenity
{
Id = 4,
VillaId = 1,
Name = "1 king bed and 1 sofa bed"
},
new Amenity
{
Id = 5,
VillaId = 2,
Name = "Private Plunge Pool"
}, new Amenity
{
Id = 6,
VillaId = 2,
Name = "Microwave and Mini Refrigerator"
}, new Amenity
{
Id = 7,
VillaId = 2,
Name = "Private Balcony"
}, new Amenity
{
Id = 8,
VillaId = 2,
Name = "king bed or 2 double beds"
},
new Amenity
{
Id = 9,
VillaId = 3,
Name = "Private Pool"
}, new Amenity
{
Id = 10,
VillaId = 3,
Name = "Jacuzzi"
}, new Amenity
{
Id = 11,
VillaId = 3,
Name = "Private Balcony"
});
}
}
}
@@ -0,0 +1,64 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WhiteLagoon.Application.Common.Interfaces;
using WhiteLagoon.Application.Common.Utility;
using WhiteLagoon.Domain.Entities;
namespace WhiteLagoon.Infrastructure.Data
{
public class DbInitializer : IDbInitializer
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly RoleManager<IdentityRole> _roleManager;
private readonly ApplicationDbContext _db;
public DbInitializer(
UserManager<ApplicationUser> userManager,
RoleManager<IdentityRole> roleManager,
ApplicationDbContext db)
{
_roleManager = roleManager;
_userManager = userManager;
_db = db;
}
public void Initialize()
{
try
{
if (_db.Database.GetPendingMigrations().Count() > 0)
{
_db.Database.Migrate();
}
if (!_roleManager.RoleExistsAsync(SD.Role_Admin).GetAwaiter().GetResult())
{
_roleManager.CreateAsync(new IdentityRole(SD.Role_Admin)).Wait();
_roleManager.CreateAsync(new IdentityRole(SD.Role_Customer)).Wait();
_userManager.CreateAsync(new ApplicationUser
{
UserName = "admin@dotnetmastery.com",
Email = "admin@dotnetmastery.com",
Name = "Bhrugen Patel",
NormalizedUserName = "ADMIN@DOTNETMASTERY.COM",
NormalizedEmail = "ADMIN@DOTNETMASTERY.COM",
PhoneNumber = "1112223333",
}, "Admin123*").GetAwaiter().GetResult();
ApplicationUser user = _db.ApplicationUsers.FirstOrDefault(u => u.Email == "admin@dotnetmastery.com");
_userManager.AddToRoleAsync(user, SD.Role_Admin).GetAwaiter().GetResult();
}
}
catch (Exception e)
{
throw;
}
}
}
}