예제 #1
0
        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();
        }
예제 #2
0
 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();
 }
예제 #3
0
        // 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(); });
        }
예제 #4
0
 public UserRepository(PhotoDBContext context)
 {
     _context = context;
 }
예제 #5
0
 public RoleController()
 {
     context = new PhotoDBContext();
 }
예제 #6
0
 public ActionResult Index()
 {
     var context = new PhotoDBContext();
     return View(context.Users.ToList());
 }
예제 #7
0
 public PhotoRepository(PhotoDBContext context)
 {
     this._context = context;
 }
예제 #8
0
 public PhotoController(PhotoDBContext context)
 {
     unitOfWork = new UnitOfWork(context);
 }
예제 #9
0
        public ActionResult Upload(int? albumID)
        {
            var context = new PhotoDBContext();

            ViewBag.Albums = new SelectList(context.Albums.ToList(), "AlbumID", "Name", albumID);
            return View();
        }
예제 #10
0
        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;
            }
        }
예제 #11
0
 public UnitOfWork(PhotoDBContext context)
 {
     this.context = context;
 }
예제 #12
0
 public UnitOfWork()
 {
     this.context = new PhotoDBContext();
 }