示例#1
0
        public async Task <IActionResult> Create(UserViewModel userViewModel)
        {
            UserViewModel u = userViewModel;

            User user = userViewModel.user;

            user.Adresses = new List <UserAddress> {
                userViewModel.address
            };

            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                var userId = user.UserId;
                return(RedirectToAction("Index", new { id = userId }));
            }
            return(View(nameof(Index)));
        }
        public async Task <IActionResult> Create(int?userId, [Bind("Id,Description,Address,Number,Neighborhood,City,State,Complement,UserId")] UserAddress address)
        {
            ViewBag.UserId = userId;
            if (ModelState.IsValid)
            {
                _context.Add(address);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", new { id = userId }));
            }
            return(RedirectToAction("Index", "User", new { id = userId }));
            // return View("~/Views/User/Index");
        }