Esempio n. 1
0
        // POST api/Pictures
        public HttpResponseMessage PostPicture(Picture picture)
        {
            if (ModelState.IsValid)
            {
                db.Pictures.Add(picture);
                db.SaveChanges();

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, picture);
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = picture.Id }));
                return response;
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Esempio n. 2
0
        // PUT api/Pictures/5
        public HttpResponseMessage PutPicture(Guid id, Picture picture)
        {
            if (ModelState.IsValid && id == picture.Id)
            {
                db.Entry(picture).State = EntityState.Modified;

                try
                {
                    db.SaveChanges();
                }
                catch (DbUpdateConcurrencyException)
                {
                    return Request.CreateResponse(HttpStatusCode.NotFound);
                }

                return Request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Von einem hochgeladenen File, Bild und Thumbnail speichern.
        /// </summary>
        /// <param name="file"></param>
        private void _RequestToPicture(HttpPostedFileBase file)
        {
            var thumbnailStream = new MemoryStream();
            var resizedStream = new MemoryStream();

            _ResizePictures(file.InputStream, resizedStream, 400, 400);
            _ResizePictures(file.InputStream, thumbnailStream, 100, 100);

            var picture = new Picture() {
                Id = Guid.NewGuid(),
                Name = Path.GetFileName(file.FileName)
            };

            var storageAccount = _getStorageAccount();

            var blobClient = storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("pictures");
            _PutPicture(resizedStream, picture.Id.ToString(), container);
            _PutPicture(thumbnailStream, picture.Id.ToString() + "_t", container);

            db.Pictures.Add(picture);
        }
Esempio n. 4
0
        /// <summary>
        /// Bilder zum Produkt hinzufügen.
        /// </summary>
        /// <param name="product"></param>
        /// <param name="pictureIds">Komma-getrennte Guids.</param>
        private void _SetProductPictures(Product product, IEnumerable<Guid> guids)
        {
            var gs = guids.ToArray();

            // Erstmal alle Bilder vom Produkt entfernen, die nicht mehr dazu gehören.
            var toRemove = product.Pictures.Where(p => !guids.Contains(p.Id)).ToArray();
            foreach (var p in toRemove) { product.Pictures.Remove(p); }

            for(var i=0; i<gs.Count(); i+=1) {
                var id = gs[i];
                var pp = product.Pictures.FirstOrDefault(p => p.Id == id);
                if (pp == null) {
                    pp = new Picture() {
                        ProductId = product.Id,
                        //Picture = _GetPictureById(id)
                    };

                    throw new NotImplementedException();

                    product.Pictures.Add(pp);
                }

                // Bilder reihen.
                pp.Pos = i;
            }
        }