Exemplo n.º 1
0
        private void EditSelectedTask()
        {
            EditTask dialog = new EditTask();

            if (tasksListBox.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem item = tasksListBox.SelectedItems[0];

            if (item == null)
            {
                return;
            }
            TaskTodo task = item.Tag as TaskTodo;

            dialog.LoadTask(task);
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                updateList(task);
                //updateTaskStatus(item, task);
                //tasksListBox.Refresh();
                Config.Tasks.SaveTasks();
            }
        }
Exemplo n.º 2
0
        public async Task <Task_Output> AddTodo(Task_Input task_Input)
        {
            var task = new TaskTodo
            {
                Title  = task_Input.Title.Trim(),
                isDone = false,
                End_At = task_Input.End_At,
                UserId = task_Input.UserId
            };

            unitOfWork.GetRepository <TaskTodo>().Add(task);

            var rs = await unitOfWork.SaveChangesAsync();

            if (rs <= 0)
            {
                return(null);
            }
            return(new Task_Output
            {
                Id = task.Id,
                Title = task_Input.Title,
                IsDone = false,
                End_At = task_Input.End_At
            });
        }
        public async Task <ServiceResponse <GetTaskTodoDTO> > UpdateTaskTodo(UpdateTaskTodoDTO updatedTaskTodo)
        {
            ServiceResponse <GetTaskTodoDTO> serviceResponse = new ServiceResponse <GetTaskTodoDTO>();

            try
            {
                TaskTodo dbTaskTodo = await _context.TasksTodo.Include(c => c.User).FirstOrDefaultAsync(c => c.Id == updatedTaskTodo.Id);

                if (dbTaskTodo.User.Id == GetUserId())
                {
                    dbTaskTodo.Title       = updatedTaskTodo.Title;
                    dbTaskTodo.Description = updatedTaskTodo.Description;
                    dbTaskTodo.Status      = updatedTaskTodo.Status;

                    _context.TasksTodo.Update(dbTaskTodo);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = _mapper.Map <GetTaskTodoDTO>(dbTaskTodo);
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Task not found.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
Exemplo n.º 4
0
        public void SaveTodo(TaskTodo model)
        {
            var subTask = Core.TaskManager.GetSubTask(model.SubTaskId);

            model.CreatorId = Identity.ID;
            Core.TaskManager.SaveTodo(model);

            Core.UserFormInfoManager.Save(new UserFormInfo
            {
                InfoId     = subTask.TaskId,
                UserId     = model.ToUserId,
                FlowStatus = FlowStatus.Doing
            });

            var feed = new Feed
            {
                InfoId     = subTask.TaskId,
                ToUserId   = model.ToUserId,
                Title      = model.Content,
                FromUserId = Identity.ID,
                Type       = FeedType.Task,
                Action     = UserAction.Create,
            };

            Core.FeedManager.Save(feed);
            Core.MessageManager.Add(feed);
        }
        public async Task <ServiceResponse <List <GetTaskTodoDTO> > > DeleteTaskTodo(int id)
        {
            ServiceResponse <List <GetTaskTodoDTO> > serviceResponse = new ServiceResponse <List <GetTaskTodoDTO> >();

            try
            {
                TaskTodo dbTaskTodo =
                    await _context.TasksTodo.FirstOrDefaultAsync(c => c.Id == id && c.User.Id == GetUserId());

                if (dbTaskTodo != null)
                {
                    _context.TasksTodo.Remove(dbTaskTodo);
                    await _context.SaveChangesAsync();

                    serviceResponse.Data = (_context.TasksTodo.Where(c => c.User.Id == GetUserId())
                                            .Select(c => _mapper.Map <GetTaskTodoDTO>(c))).ToList();
                }
                else
                {
                    serviceResponse.Success = false;
                    serviceResponse.Message = "Task not found.";
                }
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }
            return(serviceResponse);
        }
        public async Task <ServiceResponse <GetTaskTodoDTO> > GetTaskTodoById(int id)
        {
            ServiceResponse <GetTaskTodoDTO> serviceResponse = new ServiceResponse <GetTaskTodoDTO>();
            TaskTodo dbTaskTodo = await _context.TasksTodo.FirstOrDefaultAsync(c => c.Id == id && c.User.Id == GetUserId());

            serviceResponse.Data = _mapper.Map <GetTaskTodoDTO>(dbTaskTodo);
            return(serviceResponse);
        }
Exemplo n.º 7
0
        private void tasksListBox_DrawItem(object sender, DrawListViewItemEventArgs e)
        {
            TaskTodo task = e.Item.Tag as TaskTodo;

            if (task == null)
            {
                e.DrawDefault = true; return;
            }

            Rectangle rIcon  = new Rectangle(e.Bounds.X + LEFT_MARGIN, e.Bounds.Y + 2, ICON_WIDTH, ICON_HEIGHT);
            int       dx     = LEFT_MARGIN + ICON_SPACE + ICON_WIDTH;
            Rectangle rIcon2 = new Rectangle(e.Bounds.X + dx, e.Bounds.Y + 2, ICON_WIDTH, ICON_HEIGHT);

            dx = LEFT_MARGIN + (ICON_WIDTH + ICON_SPACE) * 2;
            Rectangle rText = new Rectangle(e.Bounds.X + dx, e.Bounds.Y, e.Bounds.Width - dx, e.Bounds.Height);

            if ((e.State & ListViewItemStates.Selected) != 0)
            {
                e.Graphics.FillRectangle(Brushes.Coral, rText);
                //e.DrawFocusRectangle();
            }
            //else {
            //}

            int imageId = (int)task.Activity;

            if (task.IsCritical)
            {
                imageId = 150;
            }
            if (task.IsCompleted)
            {
                imageId = 82;
            }


            Image ic = iconsNotes.Images[imageId];

            e.Graphics.DrawImage(ic, rIcon);
            if (task.IsRecurring)
            {
                e.Graphics.DrawImage(iconsNotes.Images[33], rIcon2);
            }
#if DEBUG
            string dtext = string.Format("{0} {1} :({2})", task.Text, task.RemainsUntil, task.Pressure);
#else
            string dtext = string.Format("{0}  {1}", task.Text, task.RemainsUntil);
#endif
            e.Graphics.DrawString(dtext, tasksListBox.Font, new SolidBrush(taskColor(task)), rText);


            if (tasksListBox.View != View.Details)
            {
                e.DrawText();
            }
        }
Exemplo n.º 8
0
            public async Task <int> Handle(CreateTaskCommand command, CancellationToken cancellationToken)
            {
                var task = new TaskTodo();

                task.Name        = command.Name;
                task.Completed   = command.Completed;
                task.Description = command.Description;
                _context.TasksTodo.Add(task);
                await _context.SaveChanges();

                return(task.Id);
            }
        public async Task <ServiceResponse <List <GetTaskTodoDTO> > > AddTaskTodo(AddTaskTodoDTO newTaskTodo)
        {
            ServiceResponse <List <GetTaskTodoDTO> > serviceResponse = new ServiceResponse <List <GetTaskTodoDTO> >();
            TaskTodo TaskTodo = _mapper.Map <TaskTodo>(newTaskTodo);

            TaskTodo.User = await _context.Users.FirstOrDefaultAsync(u => u.Id == GetUserId());

            await _context.TasksTodo.AddAsync(TaskTodo);

            await _context.SaveChangesAsync();

            serviceResponse.Data = (_context.TasksTodo.Where(c => c.User.Id == GetUserId()).Select(c => _mapper.Map <GetTaskTodoDTO>(c))).ToList();
            return(serviceResponse);
        }
Exemplo n.º 10
0
        private void AddTask()
        {
            EditTask dialog = new EditTask();
            TaskTodo task   = new TaskTodo("");

            dialog.LoadTask(task);
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                Config.Tasks.Add(task);
                updateTaskStatus(null, task);
                tasksListBox.Refresh();
                Config.Tasks.SaveTasks();
            }
        }
Exemplo n.º 11
0
 private Color taskColor(TaskTodo task)
 {
     if (task.IsCompleted)
     {
         return(Color.Green);
     }
     if (task.IsOverdue)
     {
         return(Color.Red);
     }
     if (task.InFuture)
     {
         return(Color.Gray);
     }
     return(Color.Black);
 }
Exemplo n.º 12
0
 public void LoadTask(TaskTodo task)
 {
     activeTask = task;
     if (task == null)
     {
         return;
     }
     eTitle.Text            = task.Text;
     eActivity.SelectedItem = task.ActivityName;
     useDueDate.Checked     = task.HasDueDate;
     if (task.HasDueDate)
     {
         eDueDate.Value = task.DueDate;
     }
     else
     {
         eDueDate.Text = "";
     }
     eScope.SelectedItem  = task.ScopeName;
     useStartDate.Checked = task.HasStartDate;
     if (task.HasStartDate)
     {
         eStartDate.Value = task.StartDate;
     }
     else
     {
         eStartDate.Text = "";
     }
     eHours.Text            = task.Duration.ToString();
     eCritical.Checked      = task.IsCritical;
     groupRecurring.Enabled = false;
     if (task.Period == TodoPeriod.None)
     {
         eRecur.Checked = false;
     }
     else
     {
         eRecur.Checked         = true;
         groupRecurring.Enabled = true;
         eDays.Value            = task.RepeatCount;
         eFloating.Checked      = task.IsFloating;
         ePeriod.SelectedItem   = task.PeriodName;
     }
     eDescription.Text = task.Description;
     updateControls();
 }
Exemplo n.º 13
0
        private ListViewItem updateTaskStatus(ListViewItem item, TaskTodo task)
        {
            if (item != null)
            {
                tasksListBox.Items.Remove(item);
            }
            item             = new ListViewItem(task.Pressure.ToString("0000000"));
            item.Tag         = task;
            item.ToolTipText = task.Description;
            item.ImageIndex  = (int)task.Activity;
            //tasksListBox.Items.Add(item);

            int idx = 0;

            foreach (ListViewItem zi in tasksListBox.Items)
            {
                TaskTodo zt = zi.Tag as TaskTodo;
                if (zt.Pressure > task.Pressure)
                {
                    break;
                }
                idx++;
            }
            tasksListBox.Items.Insert(idx, item);


            if (task.IsCompleted)
            {
                item.Group = tasksListBox.Groups[GROUP_COMPLETED]; return(item);
            }
            if (task.InFuture)
            {
                item.Group = tasksListBox.Groups[GROUP_FUTURE]; return(item);
            }
            if (task.IsCritical)
            {
                item.Group = tasksListBox.Groups[GROUP_CRITICAL]; return(item);
            }
            if (task.IsOverdue)
            {
                item.Group = tasksListBox.Groups[GROUP_OVERDUE]; return(item);
            }
            item.Group = tasksListBox.Groups[GROUP_ACTIVE];
            return(item);
        }
Exemplo n.º 14
0
        private void updateList(TaskTodo theTask)
        {
            ListViewItem toselect = null;

            tasksListBox.Items.Clear();
            foreach (TaskTodo task in Config.Tasks.GetList())
            {
                if (task == theTask)
                {
                    toselect = updateTaskStatus(null, task);
                }
                else
                {
                    updateTaskStatus(null, task);
                }
            }
            tasksListBox.Refresh();
        }
Exemplo n.º 15
0
        private void tasksListBox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            ListViewItem item = tasksListBox.Items[e.Index];

            if (item == null)
            {
                return;
            }
            TaskTodo task = item.Tag as TaskTodo;

            if (task == null)
            {
                return;
            }
            task.IsCompleted = (e.NewValue == CheckState.Checked);
            updateTaskStatus(item, task);
            Config.Tasks.SaveTasks();
        }
Exemplo n.º 16
0
        // REF.: https://github.com/arkiq/AppDataBind/blob/master/App9databind2/MainPage.xaml.cs
        public List <TaskTodo> parseJArray2List(JsonArray tempJson)
        {
            List <TaskTodo> tempList = new List <TaskTodo>();

            foreach (var item in tempJson)
            {
                var obj = item.GetObject();

                TaskTodo taskTodo = new TaskTodo();

                foreach (var key in obj.Keys)
                {
                    IJsonValue value;
                    if (!obj.TryGetValue(key, out value))
                    {
                        continue;
                    }

                    switch (key)
                    {
                    case "taskId":
                        taskTodo.TaskId = value.GetString();
                        break;

                    case "taskDesc":
                        taskTodo.TaskDesc = value.GetString();
                        break;

                    case "dateCreated":
                        DateTime dt = Convert.ToDateTime(value.GetString());
                        taskTodo.DateCreated = dt;
                        break;

                    case "location":
                        taskTodo.Location = value.GetString();
                        break;
                    }
                } // inner foreach

                tempList.Add(taskTodo);
            } // outter foreach
            return(tempList);
        }     // end of json to collection converter
Exemplo n.º 17
0
        public async Task <string> deleteToDoTask(TaskTodo taskTodo)
        {
            string status     = "FAIL";                                                                                  // set default to fail, in case request doesn't go through.
            Uri    requestUri = new Uri("http://52.35.177.146:8080/yourlist/delete-task/" + taskTodo.TaskId.ToString()); // send request to URI with task id number

            Debug.WriteLine(requestUri.ToString());
            var objClient = new HttpClient(); // new http client to make a request

            try {
                HttpResponseMessage respon = await objClient.DeleteAsync(requestUri); // get response message from service

                status = await respon.Content.ReadAsStringAsync();                    // get string representation of response
            }
            catch (HttpRequestException exception) {
                // handle exception if deletion wasn't complete on server side
                Debug.WriteLine("DESCRIPTION: " + exception.Message + " STATUS CODE: " + exception.HResult);
            }

            return(status);
        }
Exemplo n.º 18
0
        public ActionResult Create(TaskTodo task)
        {
            if (ModelState.IsValid)
            {
                using (var database = new ApplicationDbContext())
                {
                    var authorId = database.Users
                                   .Where(u => u.UserName == this.User.Identity.Name)
                                   .First()
                                   .Id;

                    task.DueDate  = DateTime.ParseExact(task.DueDateString, "dd MMMM yyyy - HH:mm", CultureInfo.InvariantCulture);
                    task.AuthorId = authorId;
                    database.Tasks.Add(task);
                    database.SaveChanges();
                    //return RedirectToAction("Create");
                }
            }
            return(RedirectToAction("List"));
        }
Exemplo n.º 19
0
        // POST Request to Service. Takes TaskTodo Model as a param and return boolean to represent status
        public async Task <bool> saveToDoTask(TaskTodo taskTodo)
        {
            bool statusFlag = false;

            // for local debuggin use http://localhost:8080/
            Uri     requestUri  = new Uri("http://52.35.177.146:8080/yourlist/save-task"); // request URI
            dynamic dynamicJson = new ExpandoObject();                                     // create dynamic object that will store values for json

            // create dynamic object that representing json; add todo task data to it
            dynamicJson.taskId      = taskTodo.TaskId.ToString();
            dynamicJson.taskDesc    = taskTodo.TaskDesc.ToString();
            dynamicJson.dateCreated = taskTodo.DateCreated.ToString();
            dynamicJson.location    = taskTodo.Location;
            // Store serialized object in string to include it as body of a request
            string json = "";

            json = JsonConvert.SerializeObject(dynamicJson); // serialize json object and store it in string
            var objClient = new HttpClient();                // create Http Client to access http methods

            // try make a request
            try {
                // send a post request to service and wait for respons; store response in HttpResponseMessage object
                HttpResponseMessage respon = await objClient.PostAsync(requestUri,
                                                                       new StringContent(json, Encoding.UTF8, "application/json"));

                string responJsonText = await respon.Content.ReadAsStringAsync(); // read respons from service as string

                if (responJsonText.Equals("OK"))
                {
                    statusFlag = true;
                }
            }
            catch (HttpRequestException exception) {
                // catch Http Exception
                Debug.WriteLine("DESCRIPTION: " + exception.Message + " STATUS CODE: " + exception.HResult);
            }

            return(statusFlag);
        }
Exemplo n.º 20
0
        private void DeleteSelectedTask()
        {
            if (tasksListBox.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem item = tasksListBox.SelectedItems[0];

            if (item == null)
            {
                return;
            }
            TaskTodo task = item.Tag as TaskTodo;

            if (!task.IsCompleted)
            {
                return;
            }
            Config.Tasks.Delete(task);
            tasksListBox.Items.Remove(item);
            Config.Tasks.SaveTasks();
        }
Exemplo n.º 21
0
 public void SaveTask(TaskTodo task)
 {
     if (task == null)
     {
         return;
     }
     task.Text         = eTitle.Text;
     task.ScopeName    = eScope.SelectedItem.ToString();
     task.ActivityName = eActivity.SelectedItem.ToString();
     if (useDueDate.Checked)
     {
         task.DueDate = eDueDate.Value;
     }
     else
     {
         task.HasDueDate = false;
     }
     if (useStartDate.Checked)
     {
         task.StartDate = eStartDate.Value;
     }
     else
     {
         task.HasStartDate = false;
     }
     task.Duration   = Convert.ToDouble(eHours.Text);
     task.IsCritical = eCritical.Checked;
     if (eRecur.Checked)
     {
         task.RepeatCount = Convert.ToInt32(eDays.Value);
         task.IsFloating  = eFloating.Checked;
         task.PeriodName  = ePeriod.SelectedItem.ToString();
     }
     else
     {
         task.Period = TodoPeriod.None;
     }
     task.Description = eDescription.Text;
 }
Exemplo n.º 22
0
        private void MarkCritical()
        {
            if (tasksListBox.SelectedItems.Count < 1)
            {
                return;
            }
            ListViewItem item = tasksListBox.SelectedItems[0];

            if (item == null)
            {
                return;
            }
            TaskTodo task = item.Tag as TaskTodo;

            if (task == null)
            {
                return;
            }
            task.IsCritical = true;
            updateTaskStatus(item, task);
            tasksListBox.Refresh();
            Config.Tasks.SaveTasks();
        }
Exemplo n.º 23
0
 internal bool IsValidTask(TaskTodo task)
 {
     return(!string.IsNullOrEmpty(task.Title) && !string.IsNullOrEmpty(task.Description) && task.FinishDate >= task.CreateDate);
 }
Exemplo n.º 24
0
 public void SaveTodo(TaskTodo model)
 {
     DB.Todos.AddOrUpdate(model);
     DB.SaveChanges();
 }
Exemplo n.º 25
0
 public void RemoveTodo(TaskTodo model)
 {
     DB.Todos.Remove(model);
     DB.SaveChanges();
 }
Exemplo n.º 26
0
 public void Update(TaskTodo task)
 {
     _context.Entry(task).State = EntityState.Modified;
 }