コード例 #1
0
        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");
        }
コード例 #2
0
 /// <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");
 }