Exemple #1
0
        public async Task <IActionResult> EditEntry(IFormCollection collection)
        {
            int.TryParse(collection["inventoryEntryId"].First(), out int inventoryEntryId);
            int.TryParse(collection["albumId"].First(), out int albumId);
            int.TryParse(collection["artistId"].First(), out int artistId);
            int.TryParse(collection["recordLabelId"].First(), out int recordLabelId);
            int.TryParse(collection["stock"].First(), out int stock);
            var albumName       = collection["albumName"].First();
            var artistName      = collection["artist"].First();
            var recordLabelName = collection["recordLabel"].First();

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

            var entry = new InventoryEntry
            {
                Id    = inventoryEntryId,
                Album = new Album
                {
                    Id     = albumId,
                    Name   = albumName,
                    Type   = albumType,
                    Artist = new Artist
                    {
                        Id   = artistId,
                        Name = artistName
                    },
                    RecordLabel = new RecordLabel
                    {
                        Id   = recordLabelId,
                        Name = recordLabelName
                    }
                },
                Stock = stock
            };
            await apiInventoryController.EditInventoryEntry(entry);

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