Ejemplo n.º 1
0
 public bool AddTask(Task task)
 {
     try
     {
         if (task.ParentTaskID != null)
         {
             if (task.ParentTaskID == 0)
             {
                 task.ParentTaskID   = null;
                 task.ParentTaskName = null;
             }
             else
             {
                 task.ParentTaskName = this.GetParentTasks().Where(x => x.Id == task.ParentTaskID).Select(x => x.Text).FirstOrDefault();
             }
         }
         using (MyContext db = new MyContext())
         {
             db.Tasks.Add(task);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 2
0
        public Task GetTaskByID(int taskID)
        {
            var Task = new Task();

            using (MyContext db = new MyContext())
            {
                var TaskDetails = (from T in db.Tasks
                                   where T.TaskID == taskID
                                   select new
                {
                    T.TaskID,
                    T.TaskName,
                    T.ParentTaskID,
                    T.ParentTaskName,
                    T.StartDate,
                    T.EndDate,
                    T.Priority,
                    T.Status
                }).FirstOrDefault();
                if (TaskDetails != null)
                {
                    Task.TaskID         = TaskDetails.TaskID;
                    Task.TaskName       = TaskDetails.TaskName;
                    Task.ParentTaskID   = TaskDetails.ParentTaskID;
                    Task.ParentTaskName = TaskDetails.ParentTaskName;
                    Task.StartDate      = TaskDetails.StartDate;
                    Task.EndDate        = TaskDetails.EndDate;
                    Task.Priority       = TaskDetails.Priority;
                    Task.Status         = TaskDetails.Status;
                }
            }

            return(Task);
        }
Ejemplo n.º 3
0
        public void UpdateTaskTest_Success()
        {
            // Arrange
            var controller = new TaskController();
            var model      = new entities.Task
            {
                TaskID         = 3,
                TaskName       = "Test Task",
                ParentTaskID   = 1,
                ParentTaskName = "Task1",
                Priority       = 30,
                StartDate      = DateTime.Today,
                EndDate        = DateTime.Today.AddDays(10)
            };

            // Act
            var response = controller.UpdateTask(model);

            // Assert
            var responseResult = response as OkNegotiatedContentResult <string>;

            Assert.IsNotNull(responseResult);
            Assert.IsNotNull(responseResult.Content);
            Assert.IsTrue(responseResult.Content == "Success");
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> UpdateTask([FromBody] Task task)
        {
            if (await _taskService.GetTaskById(task.TaskId) != null)
            {
                return(Ok(await _taskService.UpdateTask(task))); //200+data
            }

            return(NotFound());
        }
Ejemplo n.º 5
0
 public bool EditTask(Task task)
 {
     try
     {
         if (task.ParentTaskID != null)
         {
             if (task.ParentTaskID == 0)
             {
                 task.ParentTaskID   = null;
                 task.ParentTaskName = null;
             }
             else
             {
                 task.ParentTaskName = this.GetParentTasks().Where(x => x.Id == task.ParentTaskID).Select(x => x.Text).FirstOrDefault();
             }
         }
         using (MyContext db = new MyContext())
         {
             var taskDB      = (from t in db.Tasks where t.TaskID == task.TaskID select t).FirstOrDefault();
             var ChildTaskDB = (from t in db.Tasks where t.ParentTaskID == task.TaskID && t.ParentTaskName != task.TaskName select t);
             if (taskDB != null)
             {
                 taskDB.TaskName       = task.TaskName;
                 taskDB.ParentTaskID   = task.ParentTaskID;
                 taskDB.ParentTaskName = task.ParentTaskName;
                 taskDB.StartDate      = task.StartDate;
                 taskDB.EndDate        = task.EndDate;
                 taskDB.Priority       = task.Priority;
                 taskDB.Status         = task.Status;
                 db.SaveChanges();
             }
             if (ChildTaskDB != null)
             {
                 foreach (var item in ChildTaskDB)
                 {
                     item.ParentTaskName = task.TaskName;
                 }
                 db.SaveChanges();
             }
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 6
0
 public IHttpActionResult UpdateTask(entities.Task editTask)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest());
         }
         _TaskBO = new TaskBO();
         _TaskBO.EditTask(editTask);
         return(Ok("Success"));
     }
     catch (Exception)
     {
         return(Ok("Error"));
     }
 }
Ejemplo n.º 7
0
        public List <Task> SearchTask(TaskSearch search)
        {
            var Tasks = new List <Task>();

            using (MyContext db = new MyContext())
            {
                var TaskDetails = (from p in db.Tasks
                                   where
                                   (search.Task == null || search.Task == p.TaskName) &&
                                   (search.ParentTaskID == null || search.ParentTaskID == 0 || search.ParentTaskID == p.ParentTaskID) &&
                                   (search.Start_Date == null || search.Start_Date == p.StartDate) &&
                                   (search.End_Date == null || search.End_Date == p.EndDate) &&
                                   (search.PriorityFrom == null || search.PriorityFrom == p.Priority) &&
                                   (search.PriorityTo == null || search.PriorityTo == p.Priority)
                                   select new
                {
                    p.TaskID,
                    p.TaskName,
                    p.ParentTaskID,
                    p.ParentTaskName,
                    p.StartDate,
                    p.EndDate,
                    p.Priority,
                    p.Status
                }).ToList();

                foreach (var item in TaskDetails)
                {
                    var T = new Task
                    {
                        TaskID         = item.TaskID,
                        TaskName       = item.TaskName,
                        ParentTaskID   = item.ParentTaskID,
                        ParentTaskName = item.ParentTaskName,
                        StartDate      = item.StartDate,
                        EndDate        = item.EndDate,
                        Priority       = item.Priority,
                        Status         = item.Status
                    };
                    Tasks.Add(T);
                }
            }
            return(Tasks);
        }
Ejemplo n.º 8
0
        public List <Task> GetAllTask()
        {
            var Tasks = new List <Task>();

            using (MyContext db = new MyContext())
            {
                var TaskDetails = (from p in db.Tasks
                                   select new
                {
                    p.TaskID,
                    p.TaskName,
                    p.ParentTaskID,
                    p.ParentTaskName,
                    p.StartDate,
                    p.EndDate,
                    p.Priority,
                    p.Status
                }).ToList();

                foreach (var item in TaskDetails)
                {
                    var T = new Task
                    {
                        TaskID         = item.TaskID,
                        TaskName       = item.TaskName,
                        ParentTaskID   = item.ParentTaskID,
                        ParentTaskName = item.ParentTaskName,
                        StartDate      = item.StartDate,
                        EndDate        = item.EndDate,
                        Priority       = item.Priority,
                        Status         = item.Status
                    };
                    Tasks.Add(T);
                }
            }
            return(Tasks);
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            try
            {
                string input;
                Console.WriteLine("Select the Action No.");
                Console.WriteLine("1.Add Task");
                Console.WriteLine("2.Update Task");
                Console.WriteLine("3.Search Task");
                Console.WriteLine("4.Delete Task");
                Console.WriteLine("5.Exit");
                input = Console.ReadLine();
                TaskBL obj = new TaskBL();
                switch (input)
                {
                case "1":
                    obj.AddTask(new TaskManager.Entities.Task()
                    {
                        TaskId = 2, TaskName = "Task22", ParentTask = "Task11", Priority = 2, SDate = DateTime.Now, EDate = DateTime.Now, TaskEndFlag = true
                    });
                    break;

                case "2":
                    Console.WriteLine("Enter Task Id");
                    string ID_Update = Console.ReadLine();
                    TaskManager.Entities.Task TskUpdate = obj.GetById(Convert.ToInt32(ID_Update));
                    Console.WriteLine("Task Details Before Update:");
                    Console.WriteLine("Task ID : " + TskUpdate.TaskId.ToString() + "\n"
                                      + "Task Name : " + TskUpdate.TaskName.ToString() + "\n"
                                      + "Priority : " + TskUpdate.Priority.ToString() + "\n");
                    Console.WriteLine("Enter New TaskName");
                    TskUpdate.TaskName = Console.ReadLine();
                    obj.UpdateTask(TskUpdate);
                    TskUpdate = obj.GetById(Convert.ToInt32(ID_Update));
                    Console.WriteLine("Task Details After Update:");
                    Console.WriteLine("Task ID : " + TskUpdate.TaskId.ToString() + "\n"
                                      + "Task Name : " + TskUpdate.TaskName.ToString() + "\n"
                                      + "Priority : " + TskUpdate.Priority.ToString() + "\n");
                    Console.ReadLine();
                    break;

                case "3":
                    Console.WriteLine("Enter Task Id to Search");
                    String ID = Console.ReadLine();
                    TaskManager.Entities.Task TskSearch = obj.GetById(Convert.ToInt32(ID));
                    Console.WriteLine("Task Details:");
                    Console.WriteLine("Task ID : " + TskSearch.TaskId.ToString() + "/n"
                                      + "Task Name : " + TskSearch.TaskName.ToString() + "/n"
                                      + "Priority : " + TskSearch.Priority.ToString() + "/n"
                                      );
                    break;

                case "4":
                    Console.WriteLine("Enter Task Id to Delete");
                    String ID_Del = Console.ReadLine();
                    obj.DeleteTask(Convert.ToInt32(ID_Del));
                    break;

                case "5":
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> CreateTask([FromBody] Task task)
        {
            var createdTask = await _taskService.CreateTask(task);

            return(CreatedAtAction("Get", new { taskId = createdTask.TaskId }, createdTask)); //201+ data
        }