public async Task <IActionResult> AddNewTask(PreTaskModel taskModel)
        {
            if ((taskModel.StartDate < DateTime.Now) || (taskModel.EndDate < DateTime.Now))
            {
                return(RedirectToAction(nameof(AddNewTask), new { currentContext = true }));
            }

            if (taskModel.StartDate >= taskModel.EndDate)
            {
                return(RedirectToAction(nameof(AddNewTask), new { invalid = true }));
            }



            if (ModelState.IsValid)
            {
                int id = await _taskRepository.AddNewTask(taskModel);

                if (id > 0)
                {
                    return(RedirectToAction(nameof(AddNewTask), new { isSuccess = true, taskId = id }));
                }
            }
            ViewBag.project = new SelectList(await _projectRepository.GetProjects(), "ID", "Title");

            return(View());
        }
예제 #2
0
        public void ShouldAddAndRetrieveTask()
        {
            var repository = new TaskRepository(_context);

            repository.AddNewTask(new Task {
                Name = "Task1", DueDate = DateTime.Today, Priority = Priority.High
            });

            var task = repository.Tasks.Single(t => t.Name == "Task1");

            Assert.AreNotEqual(0, task.RecordId);
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "ID,Name,Completed,Note")] Task task)
        {
            if (ModelState.IsValid)
            {
                _taskRepository.AddNewTask(task);
                //in order to not call the database again to get an updated task list
                var tasks = Session["Tasks"] as List <Task>; // gathering the existing task list from the session, that doesn't include the new task to be added
                tasks.Add(task);                             // using list function, ie the tasks.Add(), to add the new task in the tasks variable
                Session["Tasks"] = tasks;                    // updating the session to include the new task thats being added to the database in order to use it without calling the database to get an updated list
                return(RedirectToAction("Index"));
            }

            return(View(task));
        }
예제 #4
0
        private void AddNewTask(object sender, RoutedEventArgs e)
        {
            var addDialog = new Dialogs.AddModifyTaskDialog(_subjectRepository.GetAllSubjects());

            addDialog.ShowDialog();
            if (!addDialog.IsSelected)
            {
                return;
            }
            int insertedTaskId = _taskRepository.AddNewTask(addDialog.SelectedSubject.SubjectId,
                                                            addDialog.SelectedTaskPriority,
                                                            addDialog.SelectedDate,
                                                            addDialog.SelectedTaskDescription);

            var newTask = new TaskTableItem()
            {
                TaskTableItemSubject = addDialog.SelectedSubject,
                TaskTableItemTask    = new SubjectTask()
                {
                    DeadLineDate    = addDialog.SelectedDate,
                    SubjectId       = addDialog.SelectedSubject.SubjectId,
                    TaskPriority    = addDialog.SelectedTaskPriority,
                    TaskDescription = addDialog.SelectedTaskDescription,
                    TaskId          = insertedTaskId
                }
            };

            if ((CertainSubjectTasks.IsChecked != null &&
                 (bool)CertainSubjectTasks.IsChecked &&
                 ((Subject)AwailableSubjects.SelectedItem).SubjectId == newTask.TaskTableItemSubject.SubjectId) ||
                (CertainSubjectTasks.IsChecked != null && !(bool)CertainSubjectTasks.IsChecked) ||
                CertainSubjectTasks.IsChecked == null)
            {
                _displayedTaskTableItems.Add(newTask);
            }
            TasksGrid.Items.Refresh();
        }