Beispiel #1
0
        public async Task <AlbumViewModel> SaveAlbumSubmitAsync(AlbumViewModelSubmit model)
        {
            await Task.CompletedTask;

            long id          = 0;
            var  objectState = ObjectState.Added;

            if (!model.IsNew)
            {
                id          = model.Id;
                objectState = ObjectState.Modified;
            }

            var album = new Album
            {
                AlbumArtUrl = model.AlbumArtUrl,
                ArtistId    = model.ArtistId,
                GenreId     = model.GenreId,
                Id          = id,
                ObjectState = objectState,
                Price       = model.Price,
                Title       = model.Title
            };

            _unitOfWork.Repository <Album>().SaveAllChanges(album);

            if (model.Image != null && model.Image.Length > 0)
            {
                // full path to file in temp location
                var filePath = Path.GetTempFileName();

                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await model.Image.CopyToAsync(stream);
                }
            }

            return(model);
        }
Beispiel #2
0
        public async Task <IActionResult> SaveAlbumSubmit(AlbumViewModelSubmit model)
        {
            var albumCollection = await _albumApi.SaveAlbumSubmitAsync(model);

            return(Ok());
        }