Exemple #1
0
        public async Task <IActionResult> Create([Bind("Id,Name,Country,Director")] Museum museum)
        {
            if (ModelState.IsValid)
            {
                _context.Add(museum);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(museum));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Born,Died")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(artist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
        public async Task <IActionResult> Create([Bind("ImageUrl,Title,Year,Medium, SelectedArtistId, SelectedMuseumId")] PaintingViewModel painting)
        {
            if (ModelState.IsValid)
            {
                var p = new Painting
                {
                    ImageUrl = painting.ImageUrl,
                    Title    = painting.Title,
                    Year     = painting.Year,
                    Medium   = painting.Medium
                };
                p.Artist = await _context.Artists.FirstOrDefaultAsync(a => a.Id == painting.SelectedArtistId);

                p.Museum = await _context.Museums.FirstOrDefaultAsync(m => m.Id == painting.SelectedMuseumId);

                _context.Add(p);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(painting));
        }