public ActionResult ChangeTaskPosition(int taskId, int priority)
        {
            ProjectRepository projectRepo = new ProjectRepository();
            TaskRepository taskRepo = new TaskRepository();

            taskRepo.ChangeTaskPosition(taskId, priority);
            int projectId = taskRepo.GetTasks().FirstOrDefault(t=>t.Id == taskId).ProjectId;
            List<Task> tasks = taskRepo.GetTasks(projectId).ToList();
            int index = tasks.IndexOf(tasks.First(t => t.Id == taskId));

            //Task

            if (Request.IsAjaxRequest())
                return PartialView("TaskList", tasks);
            else
            {
                List<Project> projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);
                List<Project> result = new List<Project>();

                foreach (var project in projects)
                {
                    var temp = project.Tasks.OrderByDescending(t => t.Priority);
                    Project pr = new Project();
                    pr.Tasks = temp.ToList();
                    result.Add(pr);
                }

                return View("MyToDoList", result);
            }
        }
        public ActionResult CreateProject(string name)
        {
            ProjectRepository projectRepo = new ProjectRepository();
            List<Project> projects = new List<Project>();

            projectRepo.AddProject(new Project()
            {
                Name = name,
                Tasks = null,
                UserId = WebSecurity.CurrentUserId
            });

            projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);

            return View("MyToDoList", projects);
        }
        public ActionResult CreateTask(string task, int projectId)
        {
            TaskRepository taskRepo = new TaskRepository();
            ProjectRepository projectRepo = new ProjectRepository();
            List<Project> projects = new List<Project>();

            taskRepo.AddTask(new Task()
            {
                Description = task,
                Priority = 0,
                ProjectId = projectRepo.GetProjects(WebSecurity.CurrentUserId).Find(p => p.Id == projectId).Id,
                Deadline = DateTime.Now,
                IsDone = false
            });

            //Task taskToAdd = taskRepo.GetTasks(projectId).First(t => t.Description.Equals(task));
            //Projects.First(p => p.Id == projectId).Tasks.Add(taskToAdd);
            projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);
            return View("MyToDoList", projects);
        }
        public ActionResult MyToDoList()
        {
            ProjectRepository projectRepo = new ProjectRepository();
            //List<Project> projects = new List<Project>();

            projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);

            return View(projects);
        }
        public ActionResult MarkTaskAsDone(int taskId)
        {
            TaskRepository taskRepo = new TaskRepository();
            ProjectRepository projectRepo = new ProjectRepository();
            //Thread.Sleep(3000);
            taskRepo.SetTaskState(taskId, true);

            List<Project> projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);
            return View("MyToDoList", projects);
        }
        public ActionResult DeleteTask(int taskId)
        {
            ProjectRepository projectRepo = new ProjectRepository();
            TaskRepository taskRepo = new TaskRepository();

            taskRepo.DeleteTask(taskId);

            List<Project> projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);
            return View("MyToDoList", projects);
        }
        public ActionResult DeleteProject(int? id)
        {
            ProjectRepository projectRepo = new ProjectRepository();
            List<Project> projects = new List<Project>();

            projectRepo.DeleteProject((int)id);

            //projectRepo = new ProjectRepository();
            projects = projectRepo.GetProjects(WebSecurity.CurrentUserId);

            return View("MyToDoList", projects);
        }