コード例 #1
0
        public ActionResult New(BandContactViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            ContactInfo contact = new ContactInfo
            {
                PhoneNumber = viewModel.PhoneNumber,
                Email       = viewModel.Email,
                Facebook    = viewModel.Facebook
            };

            _context.ContactInfos.Add(contact);

            Band band = new Band
            {
                Name           = viewModel.Name,
                NrAlbumsOnSite = viewModel.NrAlbumsOnSite,
                Country        = viewModel.Country,
                YearFounded    = viewModel.YearFounded,
                ContactInfo    = contact,
            };

            _context.Bands.Add(band);
            _context.SaveChanges();

            return(RedirectToAction("Index", "Bands"));
        }
コード例 #2
0
        public ActionResult New()
        {
            // var viewModel = new BandFormViewModel();
            var viewModel = new BandContactViewModel();

            return(View(viewModel));
        }