Ejemplo n.º 1
0
        public IActionResult CreateGameForm(GameViewModel model)
        {
            if (ModelState.IsValid)
            {
                User CurrentUser = _context.Users.Include(u => u.Games).SingleOrDefault(u => u.UserId == ( int )HttpContext.Session.GetInt32("UserId"));


                Game NewGame = new Game
                {
                    Title       = model.Title,
                    Time        = model.Time,
                    Date        = model.Date,
                    Duration    = model.Duration,
                    TimeSpan    = model.TimeSpan,
                    Description = model.Description,
                    CreatedById = CurrentUser.UserId,
                    CreatedAt   = DateTime.Now,
                    UpdatedAt   = DateTime.Now
                };
                //CurrentUser.Balance += newGame.Transaction;
                _context.Games.Add(NewGame);
                _context.SaveChanges();

                NewGame = _context.Games.SingleOrDefault(a => a.Description == model.Description);
                HttpContext.Session.SetInt32("GameId", NewGame.GameId);
                return(RedirectToAction("ShowDetails", new { id = HttpContext.Session.GetInt32("GameId") }));
            }
            return(View("AddPage"));
        }
Ejemplo n.º 2
0
//**************************************************************************** */
//**************************************************************************** */
//**************************************************************************** */
        public IActionResult RegisterForm( UserViewModel model )
        {
            if( ModelState.IsValid )
            {
                PasswordHasher<UserViewModel> Hasher = new PasswordHasher<UserViewModel>();
                model.Password = Hasher.HashPassword( model, model.Password );

                User NewUser = new User
                {
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Email = model.Email,
                    Password = model.Password,
                    CreatedAt = DateTime.Now,
                    UpdatedAt = DateTime.Now
                };
                //Handle Success
                _context.Users.Add( NewUser );
                _context.SaveChanges();

                NewUser = _context.Users.SingleOrDefault( a => a.Email == model.Email );
                HttpContext.Session.SetInt32( "UserId", NewUser.UserId );
                return RedirectToAction( "Dashboard", "Game" );// Name of Method, Name of Controller
            }
            return View( "Index" );
        }