Beispiel #1
0
        public IHttpActionResult PutProductImage(int id, ProductImagesDTO modified)
        {
            if (!ProductImageExists(id))
            {
                return(NotFound());
            }

            ProductImage prodIm = (from x in db.ProductImages
                                   where x.Id == id
                                   select x).First();

            prodIm.Id        = modified.Id;
            prodIm.ProductId = modified.ProductId;
            prodIm.Url       = modified.Url;

            //db.Entry(productImage).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Beispiel #2
0
        public IHttpActionResult PostProductImage(ProductImagesDTO productImageInfo)
        {
            ProductImage newProdIm = ToEntity(productImageInfo);

            db.ProductImages.Add(newProdIm);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = newProdIm.Id }, newProdIm));
        }
Beispiel #3
0
 private ProductImage ToEntity(ProductImagesDTO pi)
 {
     return(new ProductImage()
     {
         Id = pi.Id,
         Url = pi.Url,
         ProductId = pi.ProductId
     });
 }
        public ProductImagesDTO GetByProductId(int productId)
        {
            var imagesDto        = new List <ImageDTO>();
            var productImagesDto = new ProductImagesDTO()
            {
                ProductId = productId
            };
            var images = _imageRepository.GetByProductId(productId);

            foreach (var image in images)
            {
                var imageDto = new ImageDTO();
                imageDto.Id          = image.Id;
                imageDto.ImageBase64 = image.ImageBase64;
                imagesDto.Add(imageDto);
            }

            productImagesDto.Images = imagesDto;
            return(productImagesDto);
        }