// https://stackoverflow.com/questions/42471866/how-to-create-roles-in-asp-net-core-and-assign-them-to-users private async Task CreateUserRoles(IServiceProvider serviceProvider) { RoleManager <IdentityRole> roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >(); HouseContext Context = serviceProvider.GetRequiredService <HouseContext>(); IdentityResult roleResult; bool roleCheck = await roleManager.RoleExistsAsync("Admin"); if (!roleCheck) { roleResult = await roleManager.CreateAsync(new IdentityRole("Admin")); } IdentityUser user = Context.Users.FirstOrDefault(u => u.Email == "*****@*****.**"); if (user != null) { DbSet <IdentityUserRole <string> > roles = Context.UserRoles; IdentityRole adminRole = Context.Roles.FirstOrDefault(r => r.Name == "Admin"); if (adminRole != null) { if (!roles.Any(ur => ur.UserId == user.Id && ur.RoleId == adminRole.Id)) { roles.Add(new IdentityUserRole <string>() { UserId = user.Id, RoleId = adminRole.Id }); Context.SaveChanges(); } } } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, HouseContext context, ILoggerFactory loggerFactory) { HouseService service = new HouseService(context); DbInitializer dbinitializer = new DbInitializer(service); dbinitializer.Initialize(); app.UseMvc(); }
public DownloadPersonalDataModel( UserManager <CustomUser> userManager, ILogger <DownloadPersonalDataModel> logger, HouseContext context) { _userManager = userManager; _logger = logger; _context = context; }
public IndexModel( UserManager <CustomUser> userManager, SignInManager <CustomUser> signInManager, HouseContext context) { _userManager = userManager; _signInManager = signInManager; _context = context; }
public CountersService(HouseContext context, MapperService mapperService, ILogger <CountersService> logger) { _context = context; _mapperService = mapperService; _logger = logger; _serviceName = nameof(CountersService); }
protected BaseService(HouseContext context, ILogger <CountersService> logger, DbSet <T> dbSet, string serviceName) { _context = context; _logger = logger; _dbSet = dbSet; _serviceName = serviceName; }
//initial public static void initialData(HouseContext context) { //student Initializer var students = new List <Student> { new Student { Username = "******", Password = "******", Birthday = DateTime.Parse("1994-05-02") }, new Student { Username = "******", Password = "******", Birthday = DateTime.Parse("1995-08-12") }, }; students.ForEach(s => context.Students.Add(s)); context.SaveChanges(); //staff Initializer var universityStaffs = new List <UniversityStaff> { new UniversityStaff { Username = "******", Password = "******", Birthday = DateTime.Parse("1975-11-12") } }; universityStaffs.ForEach(s => context.UniversityStaffs.Add(s)); context.SaveChanges(); //Landlord Initializer var landlords = new List <Landlord> { new Landlord { Username = "******", Password = "******", Birthday = DateTime.Parse("1979-01-12") } }; landlords.ForEach(s => context.Landlords.Add(s)); context.SaveChanges(); //advertisements Initializer var advertisements = new List <Advertisement> { new Advertisement { LandlordID = 1, Pass = 0, Title = "Good price", Description = "Initial Data(wait):city center!Welcome to southampton, just 75/week!" }, new Advertisement { LandlordID = 1, Pass = 1, Title = "Near the sear house", Description = "Initial Data(pass):close to the university of southampton, just 115/week!" }, new Advertisement { LandlordID = 1, Pass = 2, Title = "4 Room big house", Description = "Initial Data(Fail):asdasfjkakj1danjsk asdjaksdask", RefuseReason = "wrong description!" } }; advertisements.ForEach(s => context.Advertisements.Add(s)); context.SaveChanges(); }
public static void DeleteImagesByAdvertisementID(this HouseContext db, int id) { foreach (Image i in db.Images) { if (i.AdvertisementID == id) { db.Images.Remove(i); } } db.SaveChanges(); }
public DeletePersonalDataModel( UserManager <CustomUser> userManager, SignInManager <CustomUser> signInManager, ILogger <DeletePersonalDataModel> logger, HouseContext context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _context = context; }
public UserController( UserManager <CustomUser> userManager, SignInManager <CustomUser> signInManager, IOptions <AppSettings> appSettings, HouseContext context ) { _userManager = userManager; _signInManager = signInManager; _appSettings = appSettings.Value; _context = context; }
public RegisterModel( UserManager <CustomUser> userManager, SignInManager <CustomUser> signInManager, ILogger <RegisterModel> logger, IEmailSender emailSender, HouseContext context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _emailSender = emailSender; _context = context; }
public LocationController(HouseContext context) { _context = context; }
public PeriodController(HouseContext context) { _context = context; }
public EdmModelBuilder(HouseContext houseContext, IPluralizer pluralizer) { _houseContext = houseContext; _pluralizer = pluralizer; }
public HouseService(HouseContext context) { _context = context; }
public MainController(HouseContext context) { dbContext = context; }
public RoomController(IUnitOfWork uow, HouseContext context) { _uow = uow; _context = context; }
public ReservationController(IUnitOfWork uow, HouseContext context) { _uow = uow; _context = context; }
public InteriorController(HouseContext context) { _context = context; }
public EFUnitOfWork(HouseContext context) { this.db = context; }
public HouseController(HouseContext ctx) { context = ctx; }
public ProfessionController(HouseContext context) { _context = context; }
public HouseService(HouseContext context) { db = context; }
public CustomService(HouseContext _context) { context = _context; }
public HouseContext Get() { return(dataContext ?? (dataContext = new HouseContext())); }
public HousesController(HouseContext context) { _context = context; }
public InvoiceController(HouseContext context) { _context = context; }
public CustomerController(HouseContext context) { _context = context; }
public BaseRepository(HouseContext context) { Context = context; }
private void AddTestData(HouseContext context) { // NOTE: save changes inbetween ensure we have IDs for our entities // Add interior definitions for chairs and tables: // class Chair // { // public string Manufacturer {get;set;} // public string Model {get;set;} // public int Year {get;set;} // public double Weight {get;set;} // } var chairDefinition = new InteriorDefinition { Name = "Chair", }; context.Add(chairDefinition); context.SaveChanges(); context.Add(new InteriorPropertyDefinition { Name = "Manufacturer", PropertyType = InteriorPropertyType.String, PropertyName = nameof(IUserDefinedPropertyBag.StringProperty1), DefinitionID = chairDefinition.ID, Definition = chairDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Model", PropertyType = InteriorPropertyType.String, PropertyName = nameof(IUserDefinedPropertyBag.StringProperty2), DefinitionID = chairDefinition.ID, Definition = chairDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Year", PropertyType = InteriorPropertyType.Int, PropertyName = nameof(IUserDefinedPropertyBag.IntProperty1), DefinitionID = chairDefinition.ID, Definition = chairDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Weight", PropertyType = InteriorPropertyType.Double, PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty1), DefinitionID = chairDefinition.ID, Definition = chairDefinition, }); context.SaveChanges(); // class Table // { // public string Manufacturer {get;set;} // public string Model {get;set;} // public int ExpansionPanels {get;set;} // public int SuitablePersonCount {get;set;} // public double Width {get;set;} // public double Height {get;set;} // public double Depth {get;set;} // } var tableDefinition = new InteriorDefinition { Name = "Table", }; context.Add(tableDefinition); context.SaveChanges(); context.Add(new InteriorPropertyDefinition { Name = "Manufacturer", PropertyType = InteriorPropertyType.String, PropertyName = nameof(IUserDefinedPropertyBag.StringProperty1), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Model", PropertyType = InteriorPropertyType.String, PropertyName = nameof(IUserDefinedPropertyBag.StringProperty2), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "ExpansionPanels", PropertyType = InteriorPropertyType.Int, PropertyName = nameof(IUserDefinedPropertyBag.IntProperty1), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "SuitablePersonCount", PropertyType = InteriorPropertyType.Int, PropertyName = nameof(IUserDefinedPropertyBag.IntProperty2), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Width", PropertyType = InteriorPropertyType.Double, PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty1), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Height", PropertyType = InteriorPropertyType.Double, PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty2), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.Add(new InteriorPropertyDefinition { Name = "Depth", PropertyType = InteriorPropertyType.Double, PropertyName = nameof(IUserDefinedPropertyBag.DoubleProperty3), DefinitionID = tableDefinition.ID, Definition = tableDefinition, }); context.SaveChanges(); // Add some test houses and rooms (random data) var deskManufacturers = new[] { "Desk Inc.", "Desktopia", "Desk4You", "WeLoveDesks" }; var deskModels = new[] { "Dining Table", "Couch Table", "Pool Table", "Table Football Table", "Poker Table" }; var chairManufacturers = new[] { "Chair Inc.", "Chairtopia", "Chair4You", "WeLoveChairs" }; var chairModels = new[] { "Armchair", "Rocking Chair", "Stool", "Wheelchair", "Deckchair" }; var random = new Random(); for (int houseIndex = 0; houseIndex < random.Next(1, 5); houseIndex++) { var house = new House { Name = "House " + houseIndex, Address = "Main Street " + random.Next(1, 100) }; context.Add(house); context.SaveChanges(); for (int roomIndex = 0; roomIndex < random.Next(1, 10); roomIndex++) { var room = new Room { Name = house.Name + " - Room " + roomIndex, House = house, HouseID = house.ID }; context.Add(room); context.SaveChanges(); for (int tableIndex = 0; tableIndex < random.Next(1, 5); tableIndex++) { var table = new Interior { Definition = tableDefinition, DefinitionID = tableDefinition.ID, Room = room, RoomId = room.ID, StringProperty1 = deskManufacturers[random.Next(deskManufacturers.Length)], StringProperty2 = deskModels[random.Next(deskModels.Length)], IntProperty1 = random.Next(0, 2), // ExpansionPanels IntProperty2 = random.Next(4, 10), // SuitablePersonCount DoubleProperty1 = random.NextDouble() * 300, // Width (0-300cm) DoubleProperty2 = random.NextDouble() * 120, // Height (0-120cm) DoubleProperty3 = random.NextDouble() * 800, // Depth (0-800cm) }; context.Add(table); } context.SaveChanges(); for (int chairIndex = 0; chairIndex < random.Next(1, 10); chairIndex++) { var chair = new Interior { Definition = chairDefinition, DefinitionID = chairDefinition.ID, Room = room, RoomId = room.ID, StringProperty1 = chairManufacturers[random.Next(deskManufacturers.Length)], StringProperty2 = chairModels[random.Next(deskModels.Length)], IntProperty1 = random.Next(2000, DateTime.Now.Year + 1), // Year DoubleProperty1 = 500 + random.NextDouble() * 500, // Weight (500-1000g) }; context.Add(chair); } context.SaveChanges(); } } }