Ejemplo n.º 1
0
        [Authorize(Roles = "administrator")] // csak bejelentkezett adminisztrátoroknak
        public IActionResult PostImage([FromBody] ImageDTO image)
        {
            if (image == null || !_context.Buildings.Any(building => image.BuildingId == building.Id))
            {
                return(NotFound());
            }

            BuildingImage buildingImage = new BuildingImage
            {
                BuildingId = image.BuildingId,
                ImageSmall = image.ImageSmall,
                ImageLarge = image.ImageLarge
            };

            _context.BuildingImages.Add(buildingImage);

            try
            {
                _context.SaveChanges();
                return(Created(Request.GetUri() + image.Id.ToString(), image.Id)); // csak az azonosítót küldjük vissza
            }
            catch
            {
                // Internal Server Error
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 2
0
        public IActionResult GetImage(Int32 id)
        {
            BuildingImage image = _context.BuildingImages.FirstOrDefault(img => img.BuildingId == id);

            if (image == null)
            {
                return(NotFound());
            }

            // a képe átalakítjuk (kis és nagyképet egyaránt)
            return(Ok(new ImageDTO
            {
                Id = image.Id,
                BuildingId = image.BuildingId,
                ImageSmall = image.ImageSmall,
                ImageLarge = image.ImageLarge
            }));
        }
Ejemplo n.º 3
0
        public IActionResult DeleteImage(Int32 id)
        {
            BuildingImage image = _context.BuildingImages.FirstOrDefault(im => im.Id == id);

            if (image == null)
            {
                return(NotFound());
            }

            try
            {
                _context.BuildingImages.Remove(image);
                _context.SaveChanges();
                return(Ok());
            }
            catch
            {
                // Internal Server Error
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }