public async Task <IActionResult> Create([Bind("Name, Phone, Place")] Tracker tracker) { //https://localhost:44394/Trackers/Create?Place=Vision_College Models.Business data = _context.Business.FirstOrDefault(m => m.BusinessName == tracker.Place); Guid aSPNetUsersIdfk = data.ASPNetUsersIdfk; tracker.ASPNetUsersIdfk = aSPNetUsersIdfk.ToString(); tracker.Id = Guid.NewGuid(); tracker.DateIn = DateTime.Now; tracker.DateOut = DateTime.Now.AddHours(2); //incase they forget to log out SaveCookies(tracker); _context.Add(tracker); await _context.SaveChangesAsync(); //pass through the model. https://docs.microsoft.com/en-us/aspnet/core/mvc/views/overview?view=aspnetcore-3.1 // return View(nameof(LogoutTracker)); // return View(tracker); //https://exceptionnotfound.net/asp-net-core-demystified-action-results/ // return NoContent(); return(RedirectToAction("Index")); //works // return RedirectToAction("LogoutTracker"); }
public async Task <IActionResult> Create([Bind("Id,BusinessName,AdminName,BusinessAddress,Phone")] Models.Business business) { //todo add in the guid of the current logged in person to the class if (ModelState.IsValid) { // https://stackoverflow.com/questions/30701006/how-to-get-the-current-logged-in-user-id-in-asp-net-core //todo Fix usermanager // ApplicationUser applicationUser = await _userManager.GetUserAsync(User); // string userEmail = applicationUser?.Email; // will give the user's Email //todo Fix usermanager // Guid userId = Guid.Parse(applicationUser?.Id); // will give the user's Email //var userId = _userManager.FindFirstValue(ClaimTypes.NameIdentifier); // will give the user's userId // var userName = _userManager.FindFirstValue(ClaimTypes.Name); // will give the user's userName business.BusinessName = business.BusinessName.Replace(" ", "_"); //clear out spaces business.Id = Guid.NewGuid(); // business.ASPNetUsersIdfk = userId;//todo Fix usermanager _context.Add(business); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(business)); }