public ActionResult Index() { if (Request.IsAuthenticated) { string userId = User.Identity.GetUserId(); BPUser bpUser = _context.BPUsers.Where(s => s.AppId == userId).SingleOrDefault(); System.Web.HttpContext.Current.Session["UserName"] = bpUser.FirstName + " " + bpUser.LastName; } HomePageViewModel homePageViewModel = new HomePageViewModel(); return(View(homePageViewModel)); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var bpUser = new BPUser { FirstName = model.FirstName, LastName = model.LastName }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false); bpUser.AppId = user.Id; ApplicationDbContext _context = new ApplicationDbContext(); _context.BPUsers.Add(bpUser); _context.SaveChanges(); // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public ActionResult Poem(int Id) { if (Request.IsAuthenticated) { string userId = User.Identity.GetUserId(); BPUser bpUser = _context.BPUsers.Where(s => s.AppId == userId).SingleOrDefault(); System.Web.HttpContext.Current.Session["UserName"] = bpUser.FirstName + " " + bpUser.LastName; // only mark as read if not already in the database if (!_context.BPUserPoems.Any(p => p.PoemId == Id && p.BPUserId == bpUser.Id)) { // add poem to list of read poems BPUserPoems bpup = new BPUserPoems { BPUserId = bpUser.Id, PoemId = Id }; _context.BPUserPoems.Add(bpup); _context.SaveChanges(); } } PoemViewModel poemViewModel = new PoemViewModel(Id); return(View(poemViewModel.FileNameView, "_Layout", poemViewModel)); }