public ActionResult SaveProfileToProfessional(ProfessionalProfileViewModel _proProfile) { var currentId = User.Identity.GetUserId(); //if (!ModelState.IsValid) //{ // var _professional = _context.Professionals.SingleOrDefault(m => m.CurrentUserId == currentId); // var viewModel = new ProfessionalProfileViewModel() // { // Professional = _professional // }; // return View("professionalProfileForm", viewModel); //} _proProfile.Profile.WhoCreated = User.Identity.GetUserId(); _context.Profiles.Add(_proProfile.Profile); _context.SaveChanges(); var profileToLink = _context.Profiles.SingleOrDefault(m => m.WhoCreated == currentId); var professionalToGetProfile = _context.Professionals.SingleOrDefault(m => m.CurrentUserId == currentId); professionalToGetProfile.ProfileId = profileToLink.Id; _context.SaveChanges(); return(RedirectToAction("Index", "Manage")); }
public ActionResult NewProfile() { var currentId = User.Identity.GetUserId(); var userTeraz = _context.Users.FirstOrDefault(m => m.Id == currentId); var isUser = userTeraz.AppUserId != null; var isProfessional = userTeraz.ProfessionalId != null; if (isUser) { var _appUser = _context.AppUsers.SingleOrDefault(m => m.CurrentUserId == currentId); var viewModel = new UserProfileViewModel() { AppUser = _appUser }; return(View("userProfileForm", viewModel)); } if (isProfessional) { var _professional = _context.Professionals.SingleOrDefault(m => m.CurrentUserId == currentId); var viewModel = new ProfessionalProfileViewModel() { Professional = _professional }; return(View("professionalProfileForm", viewModel)); } return(RedirectToAction("Index", "Manage")); }