Beispiel #1
0
        public ActionResult TaskList()
        {
            Capstone6Entities ORM = new Capstone6Entities();

            ViewBag.TaskList = ORM.Tasks.ToList();

            return(View());
        }
Beispiel #2
0
        public ActionResult DeleteTask(string TaskID)
        {
            Capstone6Entities orm = new Capstone6Entities();
            Task Found            = orm.Tasks.Find(TaskID);

            orm.Tasks.Remove(Found);
            orm.SaveChanges();
            return(RedirectToAction("TaskList"));
        }
Beispiel #3
0
        public ActionResult SaveNewTask(Task newTask)
        {
            Capstone6Entities orm = new Capstone6Entities();

            orm.Tasks.Add(newTask);

            orm.SaveChanges();

            return(RedirectToAction("TaskList"));
        }
Beispiel #4
0
        public ActionResult RegisterNewUser(User newUser)
        {
            Capstone6Entities ORM = new Capstone6Entities();

            ORM.Users.Add(newUser);

            ORM.SaveChanges();

            return(View("Index"));
        }
Beispiel #5
0
        public ActionResult Index()
        {
            Capstone6Entities ORMuser = new Capstone6Entities();
            var userList = ORMuser.Users.ToList();

            //put user db list into select list for dropdown list
            ViewBag.allUsers = new SelectList(userList, "userID", "name");

            return(View());
        }
Beispiel #6
0
        //for testing purposes
        public ActionResult AllUserTasksView()
        {
            //1. get database
            Capstone6Entities ormListTask = new Capstone6Entities();

            //3.load items into viewbag matching userid

            ViewBag.AllTasks = ormListTask.Tasks.ToList();

            //ViewBag.theUsersTasks = ormList.Tasks.Where(u => u.userID == getTasks.userID).ToString();

            //3.return view
            return(View());
        }
Beispiel #7
0
        public ActionResult UserTasksView()
        {
            //1. get database
            Capstone6Entities ormList = new Capstone6Entities();

            //2. Get user id
            User selectUser = ormList.Users.Find(1);

            //3.load items into viewbag matching userid

            ViewBag.theUserTasks = ormList.Tasks.Where(x => x.userID == selectUser.userID).ToList();

            //3.return view
            return(View());
        }
Beispiel #8
0
        public ActionResult UserTaskDelete(Task deleteItem)
        {
            //1. create ORM
            Capstone6Entities ORMtask = new Capstone6Entities();

            //2. get old item
            Task getItem = ORMtask.Tasks.Find(deleteItem.taskID); // use edit item name to find old item

            //4. push to DB

            ORMtask.Entry(getItem).State = System.Data.Entity.EntityState.Deleted;
            ORMtask.SaveChanges();

            //5. return to the list of item
            return(RedirectToAction("UserTasksView")); // action to action instead of action to view
        }
Beispiel #9
0
        public ActionResult UserTaskComplete(int whichTasks, int currentUser)
        {
            int numberToReturn = currentUser;
            //1. create ORM
            Capstone6Entities ORMtask = new Capstone6Entities();

            //2. find item
            Task getItem = ORMtask.Tasks.Find(whichTasks); // use edit item name to find old item

            //3. change item
            getItem.isComplete = true;
            //4. push to DB
            ORMtask.Entry(getItem).State = System.Data.Entity.EntityState.Modified;
            ORMtask.SaveChanges();

            //5. return to the list of item
            return(RedirectToAction("UserTasksView", new { currentUser = numberToReturn })); // action to action instead of action to view
        }
Beispiel #10
0
        public ActionResult ChangeStatus(string TaskID)
        {
            Capstone6Entities ORM = new Capstone6Entities();
            Task Found            = ORM.Tasks.Find(TaskID);

            if (Found.Status == "incomplete")
            {
                Found.Status = "complete";
            }
            else
            {
                Found.Status = "incomplete";
            }


            ORM.Entry(Found).State = System.Data.Entity.EntityState.Modified;

            ORM.SaveChanges();
            return(RedirectToAction("TaskList"));
        }
Beispiel #11
0
        public ActionResult SignIn(User user)
        {
            Capstone6Entities ORM = new Capstone6Entities();

            List <User> users = ORM.Users.ToList();

            if (users.Where(X => X.UserName == user.UserName).ToList().Count() == 0)
            {
                ViewBag.Error = "Username does not exist";
                return(View("Error"));
            }

            User thisUser = ORM.Users.Find(user.UserName);

            if (thisUser.Password != user.Password)
            {
                ViewBag.Error = "Incorrect Password";
            }

            ViewBag.Message = $"Welcome {user.UserName}!";
            return(View("Welcome"));
        }
Beispiel #12
0
        public ActionResult AddNew(Task newTask)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Capstone6Entities ORMtask = new Capstone6Entities();

                    var searchDup = ORMtask.Tasks.Where(x => x.taskID == newTask.taskID).SingleOrDefault();

                    if (searchDup == null)
                    {
                        ORMtask.Entry(newTask).State = System.Data.Entity.EntityState.Added;
                        ORMtask.SaveChanges();

                        ViewBag.AllItems = ORMtask.Tasks.ToList <Task>();
                        return(RedirectToAction("UserTasksView"));
                    }
                    else
                    {
                        ViewBag.WhereError = "Task ID Already in database";
                        return(View("Error"));
                    }
                }
                else
                {
                    ViewBag.WhereError = "Model State Not Vaild";
                    return(View("Error"));
                }
            }
            catch (Exception)
            {
                ViewBag.WhereError = "Exception Error in Add Item";
                return(View("Error"));
            }
        }