Пример #1
0
        // update task
        public string Update(Task task)
        {
            Project project = unitOfWork.Project.Find(x => x.Id == task.ProjectId && x.State == 1);

            DateTime projectEndDate = DateTime.ParseExact(project.EndDate, "MM/dd/yyyy", null);
            DateTime taskEndDate    = DateTime.ParseExact(task.DueDate, "MM/dd/yyyy", null);

            DateTime startDate = DateTime.ParseExact(project.StartDate, "MM/dd/yyyy", null);

            if (projectEndDate > taskEndDate && startDate < taskEndDate)
            {
                unitOfWork.Tasks.Update(task);
                int rowsAffected = unitOfWork.Complete();

                if (rowsAffected > 0)
                {
                    return("1");
                }
                else
                {
                    return(Alert.AlertGenerate("Falied", "Falied", "Failed to Edit Task"));
                }
            }
            else
            {
                return(Alert.AlertGenerate("Falied", "Failed", "Invalid Date"));
            }
        }
Пример #2
0
        public IActionResult Edit(int id, int projectId)
        {
            var authData = HttpContext.Session.GetString("userInfo");

            if (authData != "")
            {
                User user = JsonConvert.DeserializeObject <User>(authData);

                if (userAccess.HasAccess(user.Id, 2, user.DesignationId))
                {
                    int userId = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));

                    Task task = taskManager.GetTaskByTaskId(id);

                    if (task.ByUserId == userId)
                    {
                        ViewBag.Projects      = projectManager.GetProjectsForDropDown();
                        ViewBag.Users         = userManager.GetAssignedUserDropDownForEdit(task.ProjectId);
                        ViewData["ProjectId"] = projectId;

                        return(View(task));
                    }

                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(RedirectToAction("AccessDenied", "Home"));
                }
            }
            else
            {
                HttpContext.Session.SetString("userInfo", "");

                return(RedirectToAction("Login", "LogIn"));
            }
        }
Пример #3
0
        public IActionResult Add(Task task)
        {
            var authData = HttpContext.Session.GetString("userInfo");

            if (authData != "")
            {
                User user = JsonConvert.DeserializeObject <User>(authData);

                if (userAccess.HasAccess(user.Id, 2, user.DesignationId))
                {
                    if (ModelState.IsValid)
                    {
                        task.ByUserId = user.Id;
                        task.State    = 1;
                        task.Seen     = 0;

                        ViewData["Message"] = taskManager.Save(task);
                    }
                    else
                    {
                        ViewData["Message"] = Alert.AlertGenerate("Falied", "Falied", "Fill up all fields correctly");;
                    }

                    ViewBag.Projects = projectManager.GetProjectsForDropDown();
                    return(View());
                }
                else
                {
                    return(RedirectToAction("AccessDenied", "Home"));
                }
            }
            else
            {
                HttpContext.Session.SetString("userInfo", "");

                return(RedirectToAction("Login", "LogIn"));
            }
        }
Пример #4
0
        // remove tasks
        public IActionResult Remove(int id, int projectId)
        {
            var authData = HttpContext.Session.GetString("userInfo");

            if (authData != "")
            {
                User user = JsonConvert.DeserializeObject <User>(authData);

                if (userAccess.HasAccess(user.Id, 2, user.DesignationId))
                {
                    Task task   = taskManager.GetTaskByTaskId(id);
                    int  userId = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));

                    if (task.ByUserId == userId)
                    {
                        task.State = 0;

                        taskManager.Update(task);
                        return(RedirectToAction("Details", "Project", new { id = projectId }));
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(RedirectToAction("AccessDenied", "Home"));
                }
            }
            else
            {
                HttpContext.Session.SetString("userInfo", "");

                return(RedirectToAction("Login", "LogIn"));
            }
        }
Пример #5
0
        public IActionResult Edit(Task task, int projectId)
        {
            var authData = HttpContext.Session.GetString("userInfo");

            if (authData != "")
            {
                User user = JsonConvert.DeserializeObject <User>(authData);

                if (userAccess.HasAccess(user.Id, 2, user.DesignationId))
                {
                    int userId = Convert.ToInt32(HttpContext.Session.GetInt32("UserId"));

                    if (userId == task.ByUserId)
                    {
                        if (ModelState.IsValid)
                        {
                            task.State = 1;
                            task.Seen  = 0;
                            string updated = taskManager.Update(task);

                            if (updated.Equals("1"))
                            {
                                return(RedirectToAction("Details", "Project", new { id = projectId }));
                            }
                            else
                            {
                                ViewData["Message"] = updated;

                                ViewBag.Projects = projectManager.GetProjectsForDropDown();
                                ViewBag.Users    = userManager.GetAssignedUserDropDownForEdit(userId);

                                return(View(task));
                            }
                        }
                        else
                        {
                            ViewData["Message"] = Alert.AlertGenerate("Failed", "Failed", "Fill up all fields correctly");

                            ViewBag.Projects = projectManager.GetProjectsForDropDown();
                            ViewBag.Users    = userManager.GetAssignedUserDropDownForEdit(userId);

                            return(View(task));
                        }
                    }
                    else
                    {
                        return(NotFound());
                    }
                }
                else
                {
                    return(RedirectToAction("AccessDenied", "Home"));
                }
            }
            else
            {
                HttpContext.Session.SetString("userInfo", "");

                return(RedirectToAction("Login", "LogIn"));
            }
        }