public void Seed(PhotoDBContext context) { Photo pic1 = new Photo() { Name = "Italia", Colour = " Grey", Price = 55, DateCreated = DateTime.Parse("2018-11-29"), Type = "Portrait", }; context.Photo.Add(pic1); context.SaveChanges(); }
public static void Main(string[] args) { using (var ctx = new PhotoDBContext()) { var location = new Location() { Adress = "gidoon 2//7", LocationID = "123456" }; var session = new Session() { Location = location, SessionID = "ParkHaYarkon" }; ctx.Locations.Add(location); ctx.Sessions.Add(session); ctx.SaveChanges(); } BuildWebHost(args).Run(); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { using (var scope = app.ApplicationServices.CreateScope()) { PhotoDBContext context = scope.ServiceProvider.GetService <PhotoDBContext>(); context.Database.EnsureDeleted(); // only in dev mode. never in prod mode or the whole database will be lost. context.Database.EnsureCreated(); IDBInitialiser DbInit = scope.ServiceProvider.GetService <IDBInitialiser>(); DbInit.Seed(context); } app.UseDeveloperExceptionPage(); } if (env.IsProduction()) { using (var scope = app.ApplicationServices.CreateScope()) { PhotoDBContext context = scope.ServiceProvider.GetService <PhotoDBContext>(); context.Database.EnsureCreated(); IDBInitialiser dbInitializer = scope.ServiceProvider.GetService <IDBInitialiser>(); dbInitializer.Seed(context); } } app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "Photo API"); options.RoutePrefix = ""; }); app.UseHttpsRedirection(); app.UseRouting(); app.UseCors(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public UserRepository(PhotoDBContext context) { _context = context; }
public RoleController() { context = new PhotoDBContext(); }
public ActionResult Index() { var context = new PhotoDBContext(); return View(context.Users.ToList()); }
public PhotoRepository(PhotoDBContext context) { this._context = context; }
public PhotoController(PhotoDBContext context) { unitOfWork = new UnitOfWork(context); }
public ActionResult Upload(int? albumID) { var context = new PhotoDBContext(); ViewBag.Albums = new SelectList(context.Albums.ToList(), "AlbumID", "Name", albumID); return View(); }
public SelectUserRolesViewModel(ApplicationUser user) : this() { this.FirstName = user.FirstName; this.LastName = user.LastName; this.UserName = user.UserName; var context = new PhotoDBContext(); var allRoles = context.Roles; foreach (var role in allRoles) { var rvm = new SelectRoleEditorViewModel(role); Roles.Add(rvm); } foreach (var userRole in user.Roles) { //var checkUserRole = this.Roles.Find(r => r.RoleName == userRole. //checkUserRole.Selected = true; } }
public UnitOfWork(PhotoDBContext context) { this.context = context; }
public UnitOfWork() { this.context = new PhotoDBContext(); }