Beispiel #1
0
        bool IsItMine(short?id)
        {
            var user = new GalleryContext().User.Where(x => x.login == User.Identity.Name).FirstOrDefault();

            return(user.Gallery.Any(x => x.id == id));
        }
 public PhotosController(GalleryContext context, IHttpContextAccessor httpContextAccessor)
 {
     _context             = context;
     _httpContextAccessor = httpContextAccessor;
 }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, GalleryContext galleryContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }


            app.UseHttpsRedirection();


            loggerFactory.AddConsole();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseStatusCodePages(async context =>
                {
                    context.HttpContext.Response.ContentType = "text/plain";

                    await context.HttpContext.Response.WriteAsync(
                        "Status code page, status code: " +
                        context.HttpContext.Response.StatusCode);
                });
            }

            app.UseAuthentication();
            app.UseStaticFiles();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                // Map from Image (entity) to Image, and back
                cfg.CreateMap <Image, ImageGallery.Model.Image>().ReverseMap();

                // Map from ImageForCreation to Image
                // Ignore properties that shouldn't be mapped
                cfg.CreateMap <ImageGallery.Model.ImageForCreation, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());

                // Map from ImageForUpdate to Image
                // ignore properties that shouldn't be mapped
                cfg.CreateMap <ImageGallery.Model.ImageForUpdate, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());
            });

            AutoMapper.Mapper.AssertConfigurationIsValid();

            // ensure DB migrations are applied
            galleryContext.Database.Migrate();

            // seed the DB with data
            galleryContext.EnsureSeedDataForContext();

            app.UseMvc();
        }
Beispiel #4
0
 public PhotosController()
 {
     db = new GalleryContext();
 }
 public UserRoleRepository(GalleryContext context)
     : base(context)
 {
 }
 public PhotoRepository(GalleryContext context)
     : base(context)
 {
 }
Beispiel #7
0
        public ReleaseQueryResult SearchReleases2(
            string searchText,
            string whereClause,
            string orderByClause,
            int?skip,
            int?take,
            Dictionary <string, string> requestContext)
        {
            //Check for vsix specific search. VS does this when checking for updates. If we don't return only the matching vsix, the update functionality in VS doesn't work properly
            var vsixid = ParseVsixId(whereClause);

            var orderBy = OrderByEnum.Ranking;

            if (orderByClause.Contains("Rating"))
            {
                orderBy = OrderByEnum.Rating;
            }
            if (orderByClause.Contains("LastModified"))
            {
                orderBy = OrderByEnum.LastModified;
            }
            if (orderByClause.Contains("DownloadCount"))
            {
                orderBy = OrderByEnum.DownloadCount;
            }
            if (orderByClause.Contains("Name"))
            {
                orderBy = OrderByEnum.Name;
            }
            if (orderByClause.Contains("Author"))
            {
                orderBy = OrderByEnum.Author;
            }

            var orderByDirection = OrderByDirection.Desc;

            if (orderByClause.Contains(" asc"))
            {
                orderByDirection = OrderByDirection.Asc;
            }
            var result = new ReleaseQueryResult();

            using (var ctx = new GalleryContext())
            {
                IEnumerable <Model.Release> releases = null;

                if (!String.IsNullOrEmpty(vsixid))
                {
                    releases = ctx.ReleasesWithStuff.ToList().Where(r => r.Extension.VsixId == vsixid);
                }
                else if (orderBy == OrderByEnum.DownloadCount)
                {
                    if (orderByDirection == OrderByDirection.Desc)
                    {
                        releases = ctx.ReleasesWithStuff.OrderByDescending(r => r.DownloadCount);
                    }
                    else
                    {
                        releases = ctx.ReleasesWithStuff.OrderBy(r => r.DownloadCount);
                    }
                }
                else if (orderBy == OrderByEnum.Rating || orderBy == OrderByEnum.Ranking)
                {
                    if (orderByDirection == OrderByDirection.Desc)
                    {
                        releases = ctx.ReleasesWithStuff.ToList().OrderByDescending(r => r.GetAverageRating());
                    }
                    else
                    {
                        releases = ctx.ReleasesWithStuff.ToList().OrderBy(r => r.GetAverageRating());
                    }
                }
                else if (orderBy == OrderByEnum.Name)
                {
                    if (orderByDirection == OrderByDirection.Asc)
                    {
                        releases = ctx.ReleasesWithStuff.ToList().OrderByDescending(r => r.Extension.Name);
                    }
                    else
                    {
                        releases = ctx.ReleasesWithStuff.ToList().OrderBy(r => r.Extension.Name);
                    }
                }

                if (releases == null)
                {
                    releases = ctx.ReleasesWithStuff;
                }

                result.TotalCount = ctx.ReleasesWithStuff.Count();
                //We should find a way to get the base uri for the service, ugly hack ahead
                var host = OperationContext.Current.IncomingMessageHeaders.To.AbsoluteUri;
                var root = host.Replace("GalleryService.svc", "");
                result.Releases = releases.ToList().Select(r => new Release(r, root)).ToArray();
            }

            return(result);
        }
 public GenericRepository(GalleryContext context)
 {
     _context = context;
 }
 public GalleryRepository(GalleryContext galleryContext)
 {
     _context = galleryContext ??
                throw new ArgumentNullException(nameof(galleryContext));
 }
Beispiel #10
0
 public PhotoRepository(GalleryContext galleryContext)
 {
     _galleryDB = galleryContext;
 }
Beispiel #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            GalleryContext gc = new GalleryContext();
        }
 public DeleteCommentCommand(ApplicationDbContext dataContext,
                             GalleryContext galleryContext)
 {
     _dataContext    = dataContext;
     _galleryContext = galleryContext;
 }
Beispiel #13
0
 public TokenRepository(GalleryContext context)
     : base(context)
 {
 }
 public EntityBaseRepository(GalleryContext context)
 {
     _context = context;
 }
Beispiel #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, GalleryContext galleryContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        // Ensure generic 500 status code on server-side error.
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected error occurred. Try again later.");
                    });
                });
            }

            app.UseStaticFiles();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                // Map from Image (entity) to Image, and back
                cfg.CreateMap <Image, Model.Image>().ReverseMap();

                // Map from ImageForCreate to Image
                // Ignore properties that shouldn't be mapped
                cfg.CreateMap <Model.ImageForCreate, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());

                // Map from ImageForUpdate to Image
                // ignore properties that shouldn't be mapped
                cfg.CreateMap <Model.ImageForUpdate, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());
            });

            AutoMapper.Mapper.AssertConfigurationIsValid();

            // ensure DB migrations are applied
            galleryContext.Database.Migrate();

            // seed the DB with data
            galleryContext.EnsureSeedDataForContext();

            // In ASP.NET Core 2.0, this is done in ConfigureService
            //app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
            //{
            //    Authority = "https://localhost:44385/",
            //    RequireHttpsMetadata = true,
            //    ApiName = "imagegalleryapi"
            //});

            app.UseAuthentication();

            app.UseMvc();
        }
 public CategoryController(GalleryContext context)
 {
     _context = context;
 }
Beispiel #17
0
 public GalleryRepository(GalleryContext galleryContext) => _context = galleryContext;
Beispiel #18
0
 public UserProfileRepository(GalleryContext context) : base(context)
 {
     _context = context;
 }
 public GalleryRepository(GalleryContext context, IPropertyMappingService propertyMappingService)
 {
     this.context = context;
     this.propertyMappingService = propertyMappingService;
 }
Beispiel #20
0
 public GalleryContext Get()
 {
     return(_galleryContext ?? (_galleryContext = new GalleryContext()));
 }
Beispiel #21
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, GalleryContext galleryContext)
        {
            loggerFactory.AddConsole();
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        // ensure generic 500 status code on fault.
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync("An unexpected fault happened. Try again later.");
                    });
                });
            }
            app.UseStaticFiles();

            AutoMapper.Mapper.Initialize(cfg =>
            {
                // Map from Image (entity) to Image, and back
                cfg.CreateMap <Image, Model.Image>().ReverseMap();

                // Map from ImageForCreation to Image
                // Ignore properties that shouldn't be mapped
                cfg.CreateMap <Model.ImageForCreation, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());

                // Map from ImageForUpdate to Image
                // ignore properties that shouldn't be mapped
                cfg.CreateMap <Model.ImageForUpdate, Image>()
                .ForMember(m => m.FileName, options => options.Ignore())
                .ForMember(m => m.Id, options => options.Ignore())
                .ForMember(m => m.OwnerId, options => options.Ignore());
            });

            AutoMapper.Mapper.AssertConfigurationIsValid();

            // ensure DB migrations are applied
            galleryContext.Database.Migrate();

            // seed the DB with data
            galleryContext.EnsureSeedDataForContext();

            app.UseMvc();
        }
Beispiel #22
0
 public UserRepository(GalleryContext context, IRoleRepository roleReposistory)
     : base(context)
 {
     _roleReposistory = roleReposistory;
 }