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"));
        }
예제 #2
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"));
        }
예제 #3
0
 public bool IsUsernameExist(string username)
 {
     using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
     {
         var v = db.Users.Where(u => u.username == username).FirstOrDefault();
         return(v == null ? false : true);
     }
 }
예제 #4
0
 public bool IsEmailExist(string email)
 {
     using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
     {
         var v = db.Users.Where(u => u.email == email).FirstOrDefault();
         return(v == null ? false : true);
     }
 }
예제 #5
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"));
        }
예제 #7
0
        public ActionResult Login(UserLogin login, string returnUrl = "")
        {
            string message = "";

            using (PrMngSystemDBEntities db = new PrMngSystemDBEntities())
            {
                var v = db.Users.Where(u => u.username == login.username).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(v.password, Crypto.Hash(login.password)) == 0) //check two hashed passwords this is okej when is zero
                    {
                        //if user selected RememberMe
                        int    timeout   = login.rememberMe ? 525600 : 60;                                           // 525600 min is one year, otherwise 20 min
                        var    ticket    = new FormsAuthenticationTicket(login.username, login.rememberMe, timeout); //cookies
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Tasks", "Task"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }

            ViewBag.Message = message;
            return(View());
        }
        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"));
        }