public IActionResult Register(LibraryCreateViewModel viewModel) { if (!ModelState.IsValid) { return View(viewModel); } var user = _mapper.Map<LibraryUser>(viewModel); var library = _mapper.Map<Library>(viewModel); user.Library = library; // Create the session var session = new LibraryUserSession { User = user, Token = Guid.NewGuid().ToString() }; _db.Add(session); _db.SaveChanges(); Response.Cookies.Append(SesssionKeys.LibrarySessionKey, session.Token, new CookieOptions { Path = "/" }); return RedirectToAction("Index", "Home"); }
/// <summary> /// /// </summary> /// <param name="user"></param> private IActionResult CreateSession(LibraryUser user) { var session = new LibraryUserSession { User = user, Token = Guid.NewGuid().ToString() }; _db.Add(session); _db.SaveChanges(); Response.Cookies.Append(SesssionKeys.LibrarySessionKey, session.Token, new CookieOptions { Path = "/" }); return RedirectToAction("Index", "Book"); }