public IActionResult AddIdea(string Idea)
 {
     if (ModelState.IsValid)
     {
         int  ID     = (int)HttpContext.Session.GetInt32("UserID");
         User poster = _context.Users.Where(x => x.UserID == ID).SingleOrDefault();
         Idea newI   = new Idea();
         newI.UserID        = (int)HttpContext.Session.GetInt32("UserID");
         newI.Description   = Idea;
         newI.TotalLikes    = 0;
         newI.createdat     = DateTime.Now;
         newI.updatedat     = DateTime.Now;
         newI.CreatorName   = HttpContext.Session.GetString("Name");
         poster.TotalPosts += 1;
         _context.Ideas.Add(newI);
         _context.SaveChanges();
         int IdeaId = _context.Ideas.Last().IdeaID;
         return(RedirectToAction("Dash"));
     }
     else
     {
         TempData["Error"] = "You must add an idea to post and idea geezzz!!!!";
         return(RedirectToAction("Dash"));
     }
 }
Exemple #2
0
        public IActionResult CreateWedding(NewWedding wedding)
        {
            if (HttpContext.Session.GetInt32("id") == null)
            {
                return(RedirectToAction("Index", "User"));
            }
            int?user_id = HttpContext.Session.GetInt32("id");

            if (ModelState.IsValid)
            {
                Wedding newWedding = new Wedding
                {
                    Groom      = wedding.Groom,
                    Bride      = wedding.Bride,
                    Date       = wedding.Date,
                    Address    = wedding.Address,
                    Created_At = DateTime.Now,
                    Updated_At = DateTime.Now,
                    UserId     = (int)user_id
                };
                _context.Add(newWedding);
                _context.SaveChanges();
                return(RedirectToAction("Dashboard", "Home"));
            }
            return(View("NewWedding"));
        }
Exemple #3
0
        public IActionResult Create(ViewModel FormData)
        {
            System.Console.WriteLine("got over here");
            User user = FormData.regUser;

            System.Console.WriteLine("got over user");
            if (FormData.regUser != null)
            {
                System.Console.WriteLine("got over here tooo");
                if (ModelState.IsValid)
                {
                    System.Console.WriteLine("model stat valid");
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    user.Password = Hasher.HashPassword(user, user.Password);
                    System.Console.WriteLine("just before adding");
                    System.Console.WriteLine(user);
                    System.Console.WriteLine(user.Name);
                    _context.Add(user);
                    _context.SaveChanges();
                    System.Console.WriteLine("***Created a User***");
                    HttpContext.Session.SetInt32("id", user.Userid);
                    HttpContext.Session.SetString("name", user.Name);
                    HttpContext.Session.SetString("alias", user.Alias);
                    return(RedirectToAction("Ideas"));
                }
                System.Console.WriteLine("null info coming thru");
            }
            System.Console.WriteLine("User creation rejected*******");
            return(View("Index", FormData));
        }
        public IActionResult InsertChef(Chef user)
        {
            if (ModelState.IsValid)
            {
                if (user.Birthday >= DateTime.Today)
                {
                    ModelState.AddModelError("Birthday", "Date of Birth must be a date from the past");
                    return(View("NewChef"));
                }

                Chef newChef = new Chef
                {
                    FirstName = user.FirstName,
                    LastName  = user.LastName,
                    Birthday  = user.Birthday
                };
                dbContext.Add(newChef);
                dbContext.SaveChanges();
                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("NewChef"));
            }
        }
        public IActionResult PostSecret(Secret secret)
        {
            if (HttpContext.Session.GetInt32("id") == null)
            {
                return(RedirectToAction("Index", "User"));
            }
            int? user_id     = HttpContext.Session.GetInt32("id");
            User currentuser = _context.Users.SingleOrDefault(user => user.Id == user_id);

            if (ModelState.IsValid)
            {
                Secret newSecret = new Secret
                {
                    Content    = secret.Content,
                    Created_At = DateTime.Now,
                    Updated_At = DateTime.Now,
                    Creator    = currentuser,
                    UserId     = (int)user_id
                };
                _context.Add(newSecret);
                _context.SaveChanges();
                return(RedirectToAction("Secrets"));
            }
            TempData["error"] = "Your secret is not valid.";
            return(RedirectToAction("Secrets"));
        }
Exemple #6
0
        public IActionResult Create(User yourSurvey)
        {
            // Handle your form submission here
            if (ModelState.IsValid)
            {
                if (dbContext.Users.Any(u => u.Email == yourSurvey.Email))
                {
                    // Manually add a ModelState error to the Email field, with provided
                    // error message
                    ModelState.AddModelError("Email", "Email already in use!");

                    // You may consider returning to the View at this point
                    return(View("Index"));
                }
                // do somethng!  maybe insert into db?  then we will redirect
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                yourSurvey.Password = Hasher.HashPassword(yourSurvey, yourSurvey.Password);
                dbContext.Add(yourSurvey); //Adds new user into database
                dbContext.SaveChanges();
                // Console.WriteLine("Success");
                // HttpContext.Session.SetString("Active", "true");
                HttpContext.Session.SetInt32("id", yourSurvey.UserId); //Set current user to current session
                return(Redirect("account/" + yourSurvey.UserId));
            }
            else
            {
                // Oh no!  We need to return a ViewResponse to preserve the ModelState, and the errors it now contains!
                // Console.WriteLine("FAIL");
                return(View("Index"));
            }
        }
        public IActionResult New(Wedding wed)
        {
            if (HttpContext.Session.GetInt32("id") == null)
            {
                return(RedirectToAction("Logout", "User"));
            }
            ;
            if (HttpContext.Session.GetInt32("id") != (int)wed.Userid)
            {
                return(RedirectToAction("Logout", "User"));
            }
            ;
            System.Console.WriteLine("****past planning validations*****");

            if (wed.Date < DateTime.Today)
            {
                ModelState.AddModelError("Date", "Date must be today or later.");
                return(View("Plan"));
            }
            User user = _context.users.SingleOrDefault(u => u.Id == HttpContext.Session.GetInt32("id"));

            wed.Creator = user;
            _context.Add(wed);
            _context.SaveChanges();
            return(RedirectToAction("Dash"));

            System.Console.WriteLine("errors in wedding planning");
            return(View("Plan"));
        }
Exemple #8
0
        public IActionResult newProduct(Product product)
        {
            if (ModelState.IsValid)
            {
                Product addnew = dbContext.Products.SingleOrDefault(p => p.ProductName == product.ProductName);
                if (addnew != null)
                {
                    ViewBag.Message = "This product already exists in the database. Add something else!";
                    return(View("Index", product));
                }

                Product NewProduct = new Product
                {
                    ProductName        = product.ProductName,
                    ProductDescription = product.ProductDescription,
                    ProductPrice       = product.ProductPrice,
                    CreatedAt          = DateTime.Now,
                    UpdatedAt          = DateTime.Now
                };

                dbContext.Add(NewProduct);
                dbContext.SaveChanges();
                NewProduct = dbContext.Products.SingleOrDefault(p => p.ProductName == NewProduct.ProductName);
                HttpContext.Session.SetInt32("ProductId", NewProduct.ProductId);

                return(RedirectToAction("Index"));
            }
            else
            {
                return(View("Index", product));
            }
        }
Exemple #9
0
 public IActionResult CreateProduct(NewProduct NewestProduct)
 {
     System.Console.WriteLine("**********Hitting the CreateProduct Route**********");
     if (_context.products.Where(checkProduct => checkProduct.ProductName == NewestProduct.ProductName).FirstOrDefault() != null)
     {
         System.Console.WriteLine("**********ProductName already exists**********");
         ModelState.AddModelError("ProductName", "Product already exists");
         return(RedirectToAction("NewProduct", NewestProduct));
     }
     System.Console.WriteLine("**********ProductName is Unique**********");
     if (ModelState.IsValid)
     {
         Product newProduct = new Product
         {
             ProductName = NewestProduct.ProductName,
             Description = NewestProduct.Description,
             Price       = NewestProduct.Price,
             Created_At  = DateTime.Now,
             Updated_At  = DateTime.Now
         };
         _context.Add(newProduct);
         _context.SaveChanges();
         HttpContext.Session.SetInt32("prod_id", newProduct.Id);
         int?prod_id = newProduct.Id;
         System.Console.WriteLine("**********" + prod_id + "**********");
         return(Redirect($"Product/{prod_id}"));
     }
     ;
     System.Console.WriteLine("**********CreateProduct Failed**********");
     return(RedirectToAction("NewProduct", NewestProduct));
 }
Exemple #10
0
        public IActionResult Register(User NewUser)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                NewUser.password = Hasher.HashPassword(NewUser, NewUser.password);
                //Save your user object to the database
                _context.Add(NewUser);
                _context.SaveChanges();

                System.Console.WriteLine("********************Register success********************");
                Account NewAccount = new Account
                {
                    balance         = 0,
                    transaction     = 0,
                    transactionDate = DateTime.Now,
                    users_Id        = NewUser.Id
                };
                _context.Add(NewAccount);
                _context.SaveChanges();
                HttpContext.Session.SetInt32("user_id", NewUser.Id);
                System.Console.WriteLine("********************" + HttpContext.Session.GetInt32("user_id") + "********************");
                System.Console.WriteLine("********************New Account Success********************");
                return(RedirectToAction("Account"));//ad the "Registration" cshtml later
            }
            else
            {
                System.Console.WriteLine("********************Register failed********************");
                return(View("Index", NewUser));
            }
        }
Exemple #11
0
        public IActionResult Register(ViewModel FormData)
        {
            if (ModelState.IsValid)
            {
                User NewUser    = FormData.regUser;
                User emailCheck = _context.Users.SingleOrDefault(u => u.Email == NewUser.Email);
                if (emailCheck == null)
                {
                    User levelCheck = _context.Users.SingleOrDefault(u => u.UserLevel == 9);
                    if (levelCheck == null)
                    {
                        NewUser.UserLevel = 9;
                    }
                    PasswordHasher <User> Hasher = new PasswordHasher <User>();
                    NewUser.Password = Hasher.HashPassword(NewUser, NewUser.Password);
                    _context.Add(NewUser);
                    _context.SaveChanges();
                    HttpContext.Session.SetInt32("userlevel", NewUser.UserLevel);
                    HttpContext.Session.SetInt32("loggedid", NewUser.Id);


                    return(RedirectToAction("Dashboard"));
                }
                ModelState.AddModelError("regUser.Email", "Email is already registered.");
                return(View("Register", FormData));
            }
            else
            {
                ViewBag.errors = ModelState.Values;
                return(View("Register", FormData));
            }
        }
        public IActionResult addIdea(Idea idea)
        {
            int?user_id = HttpContext.Session.GetInt32("id");

            if (user_id == null)
            {
                return(Redirect("/"));
            }
            User CurrentUser = _context.Users.SingleOrDefault(user => user.Id == HttpContext.Session.GetInt32("id"));

            ViewBag.User = CurrentUser;


            if (ModelState.IsValid)
            {
                idea.Creator = CurrentUser;
                _context.Add(idea);
                _context.SaveChanges();



                return(Redirect("Ideas"));
            }
            TempData["IdeaError"] = "Please enter between 8 and 255 characters";
            ModelState.AddModelError("Content", "Please enter between 8 and 255 characters");
            return(Redirect("Ideas"));
        }
Exemple #13
0
 public void TestMethod(Master inputMaster)     //it comes in non-attached state
 {
     using (var context = new YourContext())
     {
         //there are 2 ways to attach entity.
         //First one:
         context.Master.Attach(inputMaster);
         //SecondOne:
         //var master = context.Master.Find(inputMaster.MasterId);
         //master variable will be attached
         //Modifying entity:
         inputMaster.MasterValue = new object();
         context.SaveChanges();
         //Deleting all relations:
         inputMaster.Details.Clear();
         context.SaveChanges();
         //Adding new Detail:
         var newDetail = new Detail();
         inputMaster.Details.Add(newDetail);
         context.SaveChanges();
         //deleting particular Detail:
         inputMaster.Details.Remove(newDetail);
         context.SaveChanges();
     }
 }
        public IActionResult delete_dish(Dishes deleted_dish, int dish_id)
        {
            Dishes retrievedDish = dbContext.dishes.FirstOrDefault(dish => dish.id == dish_id);

            dbContext.dishes.Remove(retrievedDish);
            dbContext.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public IActionResult Create(Dish mydish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(mydish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("New"));
 }
Exemple #16
0
    public Order Add(UserBusiness obj)
    {
        UserDAL u = new UserDAL();

        u.Name = obj.Name;
        db.UserDAL.Add(u);
        db.SaveChanges();
        //Assuming the database is generating your Id's for you
        obj.Id = u.Id;
        return(obj);
    }
Exemple #17
0
        public IActionResult NewProduct(Product newProduct)
        {
            if (ModelState.IsValid)
            {
                _context.Add(newProduct);
                _context.SaveChanges();
                HttpContext.Session.SetInt32("productId", newProduct.Id);
                return(Redirect($"ViewProduct/{newProduct.Id}"));
            }

            return(View("Index", newProduct.Id));
        }
Exemple #18
0
 public IActionResult CreateCategory(ViewModel FormData)
 {
     if (ModelState.IsValid)
     {
         _context.Add(FormData.Category);
         _context.SaveChanges();
         return(Redirect($"categories/{FormData.Category.CategoryId}"));
     }
     else
     {
         return(View("Index", FormData));
     }
 }
Exemple #19
0
        public IActionResult addMessage(Message message)
        {
            User user = _context.users.SingleOrDefault(u => u.Id == HttpContext.Session.GetInt32("id"));

            message.Userid = (int)HttpContext.Session.GetInt32("id");
            _context.Add(message);
            _context.SaveChanges();
            Message saveMessage = _context.messages.Last();

            user.Messages.Add(saveMessage);
            _context.SaveChanges();

            return(RedirectToAction("Wall"));
        }
Exemple #20
0
        public IActionResult Create(User person)
        {
            if (ModelState.IsValid)
            {
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                person.Password = Hasher.HashPassword(person, person.Password);
                _context.Add(person);
                _context.SaveChanges();
                ViewBag.num = person.Id_User;
                return(RedirectToAction("Account", new{ num = (int)ViewBag.num }));
            }

            return(View("Index"));
        }
 public IActionResult PostMessage(Message message)
 {
     if (ModelState.IsValid)
     {
         int? user_id     = HttpContext.Session.GetInt32("id");
         User CurrentUser = _context.Users.SingleOrDefault(user => user.Id == user_id);
         message.User = CurrentUser;
         System.Console.WriteLine(message);
         _context.Add(message);
         _context.SaveChanges();
         return(RedirectToAction("Wall"));
     }
     return(RedirectToAction("Wall"));
 }
Exemple #22
0
 public IActionResult Create(User person)
 {
     if (ModelState.IsValid)
     {
         PasswordHasher <User> Hasher = new PasswordHasher <User>();
         person.Password = Hasher.HashPassword(person, person.Password);
         _context.Add(person);
         _context.SaveChanges();
         System.Console.WriteLine("***Created a User***");
         HttpContext.Session.SetInt32("id", person.Id);
         return(RedirectToAction("Dash", "Home"));
     }
     System.Console.WriteLine("User creation rejected*******");
     return(View("~/Views/Home/Index.cshtml"));
 }
Exemple #23
0
 public IActionResult Newdish(Dish d)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(d);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         List <User> Allchefs = dbContext.Chef.ToList();
         ViewBag.Chefs = Allchefs;
         return(View("NewDish"));
     }
 }
        public IActionResult addMessage(Message message)
        {
            int?user_id = HttpContext.Session.GetInt32("id");

            if (ModelState.IsValid)
            {
                User CurrentUser = _context.Users.SingleOrDefault(user => user.Id == HttpContext.Session.GetInt32("id"));
                message.Creator = CurrentUser;
                _context.Add(message);
                _context.SaveChanges();
                return(Redirect($"/TheWall/{user_id}"));
            }
            ModelState.AddModelError("Content", "Please enter between 8 and 255 characters");
            return(Redirect($"/TheWall/{user_id}"));
        }
Exemple #25
0
 public IActionResult PostMessage(Message NewMessage)
 {
     System.Console.WriteLine("******Hitting the PostMessage Route******");
     if (ModelState.IsValid)
     {
         int? user_id     = HttpContext.Session.GetInt32("user_id");
         User CurrentUser = _context.users.SingleOrDefault(user => user.Id == user_id);
         NewMessage.Creator = CurrentUser;
         System.Console.WriteLine(NewMessage);
         _context.Add(NewMessage);
         _context.SaveChanges();
         return(RedirectToAction("Dashboard"));
     }
     return(RedirectToAction("Dashboard"));
 }
 public IActionResult createDish(Dish dish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(dish);
         dbContext.SaveChanges();
         return(RedirectToAction("showDishes"));
     }
     else
     {
         List <Chef> AllChefs = dbContext.Chef.ToList();
         ViewBag.allchefs = AllChefs;
         return(View("AddDish", dish));
     }
 }
        public IActionResult Signup(User user)
        {
            if (ModelState.IsValid)
            {
                //Users came from DB table name.
                if (dbContext.users.Any(u => u.Email == user.Email))
                {
                    ModelState.AddModelError("Email", "Email already in use.");
                    return(View("Signup"));
                }
                PasswordHasher <User> Hasher = new PasswordHasher <User>();
                user.Password = Hasher.HashPassword(user, user.Password);

                if (!IsValidContentType(user.ImageFile.ContentType))
                {
                    User user1 = new User();
                    ViewBag.user = user1;
                    List <User> alluser1 = dbContext.users.ToList();
                    ViewBag.allUsers = user1;
                    ViewBag.id       = HttpContext.Session.GetInt32("UserId");
                    ViewBag.Error    = "Only JPG, JPEG, or PNG";
                    return(View("Signup"));
                }

                string filename = Path.Combine(he.WebRootPath, user.ImageFile.FileName);
                user.ImageFile.CopyTo(new FileStream(filename, FileMode.Create));
                string filepath = "/" + Path.GetFileName(user.ImageFile.FileName);


                User registerUser = new User
                {
                    FirstName  = user.FirstName,
                    LastName   = user.LastName,
                    Email      = user.Email,
                    Password   = user.Password,
                    Location   = user.Location,
                    ProfileUrl = filepath
                };
                dbContext.Add(registerUser);
                dbContext.SaveChanges();

                HttpContext.Session.SetInt32("id", registerUser.UserId);
                HttpContext.Session.SetString("Name", registerUser.FirstName);
                int?id_registered = HttpContext.Session.GetInt32("id");
                return(RedirectToAction("Profile"));
            }
            return(View("Signup"));
        }
Exemple #28
0
        public IActionResult RegisterUser(RegisterUser userReg)
        {
            // if email already exists in database then throw error
            if (_context.Users.Where(user => user.Email == userReg.Email).FirstOrDefault() != null)
            {
                ModelState.AddModelError("Email", "Email already in use.");
            }
            // declare variable that stores the hashed password
            PasswordHasher <RegisterUser> hasher = new PasswordHasher <RegisterUser>();

            if (ModelState.IsValid)
            {
                User newUser = new User
                {
                    First_Name = userReg.First_Name,
                    Last_Name  = userReg.Last_Name,
                    Email      = userReg.Email,
                    // set password as the new hashed password in the database
                    Password   = hasher.HashPassword(userReg, userReg.Password),
                    Created_At = DateTime.Now,
                    Updated_At = DateTime.Now,
                };
                _context.Add(newUser);
                _context.SaveChanges();
                // set the user id to the session id
                HttpContext.Session.SetInt32("id", newUser.Id);
                int?user_id = newUser.Id;
                System.Console.WriteLine(user_id);
                return(RedirectToAction("Dashboard", "Home"));
            }
            ;
            return(View("Index"));
        }
Exemple #29
0
        public IActionResult process(int number)
        {
            User thisuser = _context.Users.SingleOrDefault(user => user.IdUsers == HttpContext.Session.GetInt32("CurrentUserId"));

            if (number < 0)
            {
                if (-1 * (number) > thisuser.balance)
                {
                    HttpContext.Session.SetString("NoMoneyError", "You do not have enough money to withdrawl");
                    return(RedirectToAction("Dashboard", "Home"));
                }
            }
            bank.Models.Transaction NewAction = new bank.Models.Transaction {
                amount    = number,
                CreatedAt = DateTime.Now,
                UpdatedAt = DateTime.Now,
                UserId    = (int)HttpContext.Session.GetInt32("CurrentUserId")
            };
            if (number >= 0)
            {
                System.Console.WriteLine("This is a deposit");
            }
            else
            {
                System.Console.WriteLine("This is a withdrawl");
            }
            _context.Transactions.Add(NewAction);
            thisuser.balance += number;
            _context.SaveChanges();
            System.Console.WriteLine("You have saved changes ******&*&*&*&*&***&&***&&*&*&*&*&*&*&*&*&*&*&*&*&*&**&*&*&*&*&**&*&");

            return(RedirectToAction("Dashboard", "Home"));
        }
Exemple #30
0
        public IActionResult RegisterUser(RegisterUser userReg)//this points to the RegisterUser model for error validation purposes they are broken up
        {
            System.Console.WriteLine("**********Hitting the register route in user controller**********");
            if (_context.ninjas.Where(checkUser => checkUser.Email == userReg.Email).FirstOrDefault() != null)
            {
                System.Console.WriteLine("**********The email was already registered in the database**********");
                ModelState.AddModelError("Email", "Email already in use");
            }
            System.Console.WriteLine("**********The email is unique, horray**********");
            PasswordHasher <RegisterUser> hasher = new PasswordHasher <RegisterUser>(); //this hashes the form pw to an encrypted pw for the db

            if (ModelState.IsValid)                                                     //this bool reconciles the form data with the model validations pointing to the RegisterUser model
            {
                User newUser = new User                                                 //instantiates a new user and sets the values in the db fields to the following data
                {
                    Name       = userReg.Name,
                    Alias      = userReg.Alias,
                    Email      = userReg.Email,
                    Password   = hasher.HashPassword(userReg, userReg.Password),//this just sets the db pw value to the hash already generated
                    Created_At = DateTime.Now,
                    Updated_At = DateTime.Now,
                };
                _context.Add(newUser);                                           //added but not saves
                _context.SaveChanges();                                          //at this point we have a new user with a unique email compared to db
                HttpContext.Session.SetInt32("user_id", newUser.Id);             //sets the newUser id into session for use downstream
                int?user_id = newUser.Id;
                System.Console.WriteLine("**********" + user_id + "**********"); //verifies the new user id
                return(RedirectToAction("Dashboard", "Home"));                   //downstream to a new controller
            }
            ;
            System.Console.WriteLine("**********Registration failed**********");
            return(View("Index"));//falied to register
        }