public Album(AlbumModel albumModel) { Title = albumModel.Title; Description = albumModel.Description; if (albumModel.Files.Any()) { Files = new List<Image>(); foreach(ImageModel file in albumModel.Files) { Files.Add(new Image { Data = file.Data, MimeType = file.MimeType, Name = file.Name }); } } }
public override async Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger, CancellationToken cancellationToken) { var provider = await content.ReadAsMultipartAsync(); var providerContent = provider.Contents.FirstOrDefault(x => x.Headers.ContentType.MediaType == "application/json"); AlbumModel album = new AlbumModel(); album = await providerContent.ReadAsAsync<AlbumModel>(); var files = provider.Contents.Where(x => x.Headers.ContentType.MediaType != "application/json").ToList(); album.Files = new List<ImageModel>(); foreach(var file in files) { album.Files.Add(new ImageModel { Data = await file.ReadAsByteArrayAsync(), Name = file.Headers.ContentDisposition.FileName.NormalizeName(), MimeType = file.Headers.ContentType.MediaType }); } return album; }