public async Task <IHttpActionResult> PutAlbum(int id, Album album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != album.AlbumID)
            {
                return(BadRequest());
            }

            db.Entry(album).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AlbumExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> PutPhotos(int id, Photo photo)
        {
            return(StatusCode(HttpStatusCode.NotImplemented));

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != photo.PhotoID)
            {
                return(BadRequest());
            }

            db.Entry(photo).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PhotosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Esempio n. 3
0
        public async Task <PhotoResult> PostPhoto(IFormFile file)
        {
            // Create the container and return a container client object
            var containerClient = await GetPhotosBlobContainer();

            // Get a reference to a blob
            var blobClient = containerClient.GetBlobClient(file.FileName);

            // Open the file and upload its data
            using var uploadFileStream = file.OpenReadStream();
            var blob = await blobClient.UploadAsync(uploadFileStream, true);

            uploadFileStream.Close();

            // Save photo in database
            var photo = new Photo
            {
                Url       = blobClient.Uri.AbsoluteUri,
                CreatedAt = DateTime.Now,
                Tags      = new List <Tag>()
            };

            _context.Photos.Add(photo);
            await _context.SaveChangesAsync();

            return(new PhotoResult
            {
                Id = photo.Id,
                Url = photo.Url,
                CreatedAt = photo.CreatedAt,
                Tags = photo.Tags.Select(t => t.Value).ToList()
            });
        }
 public async Task SaveAsync()
 {
     await _context.SaveChangesAsync();
 }