public IActionResult Create(CreateUserVM userViewModel) { if (ModelState.IsValid) { User user = new User() { AddedDate = DateTime.UtcNow, IPAddress = HttpContext.Connection.RemoteIpAddress.ToString(), Password = userViewModel.Password, Email = userViewModel.Email, UserName = userViewModel.UserName, }; UserProfile userProfile = new UserProfile { AddedDate = DateTime.UtcNow, IPAddress = HttpContext.Connection.RemoteIpAddress.ToString(), Address = userViewModel.Address, FirstName = userViewModel.FirstName, LastName = userViewModel.LastName, Phone = userViewModel.Phone, }; user.UserProfile = userProfile; _userRepository.Insert(user); _userRepository.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(userViewModel)); }
public void DeleteUser(long id) { UserProfile userProfile = _userProfileRepository.Get(id); User user = _userRepository.Get(id); _userProfileRepository.Delete(userProfile); _userRepository.Delete(user); _userRepository.SaveChanges(); }