public IActionResult Add(AddUserViewModel addUserViewModel)
        {
            if (ModelState.IsValid)
            {
                User newUser = new User
                {
                    FullName = addUserViewModel.FullName,
                    Email    = addUserViewModel.Email,
                    Username = addUserViewModel.Username,
                    Password = addUserViewModel.Password
                };


                context.Users.Add(newUser);
                context.SaveChanges();

                return(Redirect("/Login/Index"));
            }

            return(View(addUserViewModel));
        }
Ejemplo n.º 2
0
        public IActionResult Add(AddBookViewModel addUserLibraryViewModel, LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                //   Category newCategory = context.Categories.Single(c => c.ID == addUserLibraryViewModel.CategoryID);



                //   var thisUserId = (from x in context.Users
                //  where x.Username == loginViewModel.UserName
                // select x.ID).FirstOrDefault();

                //  User thisUser = context.Users.Single(c => c.ID == thisUserId && thisUserId == addUserLibraryViewModel.UserID);
                // Book = context.Users.FirstOrDefault().ID;

                Book userLibrary = new Book
                {
                    IdOfUser    = context.Users.FirstOrDefault().ID,
                    Title       = addUserLibraryViewModel.BookTitle,
                    AuthorFName = addUserLibraryViewModel.AuthorFName,
                    AuthorLName = addUserLibraryViewModel.AuthorLName,
                    BookLevel   = addUserLibraryViewModel.BookLevel,
                    Genre       = addUserLibraryViewModel.Genre,
                    // Category = newCategory,
                };


                context.Book.Add(userLibrary);
                context.SaveChanges();


                return(Redirect("/Book/Index"));

                //  return Redirect("/UserLibrary/Index");
            }



            return(View(addUserLibraryViewModel));
        }