Пример #1
0
        public async Task <IActionResult> Create(IFormCollection collection)
        {
            var albumName       = collection["albumName"].First();
            var artistName      = collection["artist"].First();
            var recordLabelName = collection["recordLabel"].First();

            int.TryParse(collection["stock"].First(), out int stock);
            Enum.TryParse(collection["albumType"].First(), out AlbumType albumType);

            var inventoryEntry = new InventoryEntry()
            {
                Album = new Album
                {
                    Artist = new Artist
                    {
                        Name = artistName
                    },
                    Name        = albumName,
                    RecordLabel = new RecordLabel
                    {
                        Name = recordLabelName
                    },
                    Type = albumType
                },
                Stock = stock
            };

            await apiInventoryController.Post(inventoryEntry);

            return(RedirectToAction("Index", "Home"));
        }