Beispiel #1
0
 public IActionResult AddTask(ToDoTask task)
 {
     ViewData["ListId"] = _currentList;
     task.CreateDate    = DateTime.Now.ToString();
     if (ModelState.IsValid)
     {
         if (task.IsMultipleTask != true)
         {
             var item = _AllLists.FirstOrDefault(a => a.Name == _currentList);
             if (item != null)
             {
                 foreach (var t in item._ToDoList)
                 {
                     if (t.Title == task.Title)
                     {
                         ModelState.AddModelError("", "Task with this Title exist! Change Title or made task Multiple.");
                         return(View(task));
                     }
                 }
             }
         }
         _client.PostToDoTaskAsync(task);
         var temp = _AllLists.FirstOrDefault(a => a.Name == _currentList);
         if (temp != null)
         {
             temp._ToDoList.Add(task);
         }
         all_tasks._ToDoList.Add(task);
         if (task.Date != null)
         {
             planned_tasks._ToDoList.Add(task);
         }
         if (task.Taskimportance.ToString() == "High")
         {
             important_tasks._ToDoList.Add(task);
         }
         if (task.Date == DateTime.Now.Date)
         {
             today_tasks._ToDoList.Add(task);
         }
         return(RedirectToAction(nameof(Index)));
     }
     ModelState.AddModelError("", "Wrong data!!!");
     return(View(task));
 }
        //Додаємо задачу
        public IActionResult AddTask(ToDoTask task, string id)
        {
            task.CreateDate = DateTime.Now.ToString();
            task.TaskListId = id;
            ToDoTasksClient tasksClient = new ToDoTasksClient();

            tasksClient.PostToDoTaskAsync(task);

            var temp = TaskLists.FirstOrDefault(a => a.Key == id).Value;

            if (temp == null)
            {
                temp = new List <ToDoTask>();
                temp.Add(task);
            }
            else
            {
                temp.Add(task);
            }
            TaskLists[id] = temp;
            return(RedirectToAction(nameof(Index)));
        }