public ActionResult EditTask(Task taskEdit)
        {
            var taskUpdate = db.Tasks.SingleOrDefault(t => t.taskID == taskEdit.taskID);
            var userInfo   = (from r in db.Users
                              where r.username == User.Identity.Name
                              select r).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                return(View(taskEdit));
            }

            if (taskUpdate != null)
            {
                taskUpdate.progress    = taskEdit.progress;
                taskUpdate.deadline    = taskEdit.deadline;
                taskUpdate.description = taskEdit.description;
                taskUpdate.status      = taskEdit.status;
                if (userInfo.roleID == 3)
                {
                    taskUpdate.assignee = userInfo.userID;
                }
                else
                {
                    taskUpdate.assignee = taskEdit.assignee;
                }

                db.SaveChanges();

                UpdateProjectProgress(taskEdit, "edit");
            }


            return(RedirectToAction("Tasks"));
        }
        public ActionResult EditTask(Task taskEdit)
        {
            var taskUpdate = db.Tasks.SingleOrDefault(t => t.taskID == taskEdit.taskID);
            var roleId     = (from r in db.Users
                              where r.username == User.Identity.Name
                              select r.roleID).FirstOrDefault();

            if (!ModelState.IsValid)
            {
                return(View(taskEdit));
            }

            if (taskUpdate != null)
            {
                //using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
                //{

                taskUpdate.progress    = taskEdit.progress;
                taskUpdate.deadline    = taskEdit.deadline;
                taskUpdate.description = taskEdit.description;
                taskUpdate.status      = taskEdit.status;
                if (roleId != 3)
                {
                    taskUpdate.assignee = taskEdit.assignee;
                }

                db.SaveChanges();
                //}
            }


            return(RedirectToAction("Tasks"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                //var projectDelete = (from p in db.Projects

                //                     where p.projectID == id

                //                     select p).FirstOrDefault();

                var projectDelete = db.Projects.Where(p => p.projectID == id).FirstOrDefault();

                //delete all tasks of project
                var listTasks = projectDelete.Tasks.ToList();
                listTasks.ForEach(x => db.Tasks.Remove(x));

                //delete project
                db.Projects.Remove(projectDelete);

                db.SaveChanges();
            }

            return(RedirectToAction("Projects"));
        }
        public ActionResult EditProject(Project projectEdit)
        {
            var projectUpdate = db.Projects.SingleOrDefault(p => p.projectID == projectEdit.projectID);

            if (!ModelState.IsValid)
            {
                return(View(projectEdit));
            }

            if (projectUpdate != null)
            {
                //using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
                //{
                var userInfo = db.Users.SingleOrDefault(u => u.username == User.Identity.Name);

                projectUpdate.project_code = projectEdit.project_code;
                projectUpdate.project_name = projectEdit.project_name;
                if (userInfo.roleID == 2)
                {
                    projectUpdate.manage = userInfo.userID;
                }
                else
                {
                    projectUpdate.manage = projectEdit.manage;
                }

                db.SaveChanges();
                //}
            }


            return(RedirectToAction("Projects"));
        }
        public ActionResult EditProject(Project projectEdit)
        {
            var projectUpdate = db.Projects.SingleOrDefault(p => p.projectID == projectEdit.projectID);

            if (!ModelState.IsValid)
            {
                return(View(projectEdit));
            }

            if (projectUpdate != null)
            {
                //using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
                //{

                projectUpdate.project_code = projectEdit.project_code;
                projectUpdate.project_name = projectEdit.project_name;
                projectUpdate.manage       = projectEdit.manage;

                db.SaveChanges();
                //}
            }


            return(RedirectToAction("Projects"));
        }
Example #6
0
        public ActionResult DeleteTaskConfirmed(int id)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                var taskDelete = db.Tasks.Where(t => t.taskID == id).FirstOrDefault();

                //remove Task from Project list of Tasks
                var project = db.Projects.SingleOrDefault(p => p.projectID == taskDelete.projectID);
                project.Tasks.Remove(taskDelete);

                //delete task
                db.Tasks.Remove(taskDelete);

                db.SaveChanges();

                UpdateProjectProgress(taskDelete, "delete");
            }

            return(RedirectToAction("Tasks"));
        }
Example #7
0
        public ActionResult Registration(User user)
        {
            bool   status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                #region//Email already exist
                var isEmailExist = IsEmailExist(user.email);
                if (isEmailExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View(user));
                }
                #endregion

                #region //Username already exist
                var isUsernameExist = IsUsernameExist(user.username);
                if (isUsernameExist)
                {
                    ModelState.AddModelError("UsernameExist", "Username already exist");
                    return(View(user));
                }
                #endregion

                #region                                                   //Passwor Hashing
                user.password        = Crypto.Hash(user.password);
                user.confirmPassword = Crypto.Hash(user.confirmPassword); //we will compare this two values
                #endregion

                user.roleID = 3;
                #region //Save data to db
                using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
                {
                    db.Users.Add(user);
                    db.SaveChanges();

                    message = "Registration successful.";
                    status  = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = status;

            return(View(user));
        }
        public ActionResult CreateProject(Project newProject)
        {
            if (!ModelState.IsValid)
            {
                return(View(newProject));
            }

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                db.Projects.Add(newProject);
                db.SaveChanges();
            }

            return(RedirectToAction("Projects"));
        }
        public ActionResult CreateTask(int id, Task newTask)
        {
            if (!ModelState.IsValid)
            {
                return(View(newTask));
            }

            newTask.projectID = id;

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                db.Tasks.Add(newTask);
                db.SaveChanges();
            }

            //add Task to list Tasks in Project
            var project = db.Projects.Find(id);

            project.Tasks.Add(newTask);

            return(RedirectToAction("Tasks"));
        }
        public ActionResult CreateProject(Project newProject)
        {
            if (!ModelState.IsValid)
            {
                return(View(newProject));
            }

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                var userInfo = db.Users.SingleOrDefault(u => u.username == User.Identity.Name);

                if (userInfo.roleID == 2)
                {
                    newProject.manage = userInfo.userID;
                }

                db.Projects.Add(newProject);
                db.SaveChanges();
            }

            return(RedirectToAction("Projects"));
        }
        public ActionResult CreateTask(int id, Task newTask)
        {
            if (!ModelState.IsValid)
            {
                return(View(newTask));
            }

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                newTask.projectID = id;

                db.Tasks.Add(newTask);
                db.SaveChanges();

                var project = db.Projects.Find(id);

                project.Tasks.Add(newTask);
            }

            UpdateProjectProgress(newTask, "create");

            return(RedirectToAction("Tasks"));
        }