Exemple #1
0
        private void AddTask(string title, string tags = null)
        {
            if (null != tags)
            {
                tags = Sanitizer.SanitizeTags(tags);
                tags = Sanitizer.DeduplicateTags(tags);
            }

            Log.Debug($"Adding a new task : {title}, Status = {(_name == "now" ? "Doing" : "Later")}, Tags = {tags}");
            var newTask = new TaskItem
            {
                TaskDescription = title,
                AddedOn         = DateTime.Now,
                Status          = _name == "now" ? "Doing" : "Later",
                Tags            = tags
            };

            _repository.AddTask(newTask);
            var success = _repository.SaveChanges();

            if (success)
            {
                Log.Information($"Added a new task : {title}, Status = {(_name == "now" ? "Doing" : "Later")}, Tags = {tags}");
                Output.WriteText($"[green]Added a new task[/] : {title}, [aqua]Status[/] = {(_name == "now" ? "Doing" : "Later")}, [aqua]Tags[/] = {tags}");
            }
            else
            {
                Log.Error($"Failed to add task.");
                Output.WriteError($"Failed to add task. Please try again.");
            }
        }
Exemple #2
0
        private void UpdateTaskDetails(int id, string title = null, string addTags = null, string removeTags = null, bool resetTags = false)
        {
            Log.Debug($"Modifying information of task [{id}]. Params -> Title: {title}, Tags: {addTags}");

            var task = _repository.GetTaskById(id);

            if (null == task)
            {
                Log.Error($"Task with ID {id} does not exist.");
                Output.WriteError($"Task with ID {id} does not exist. View all tasks with -> dewit list");
                return;
            }

            // Modify the title of the task
            if (!string.IsNullOrEmpty(title))
            {
                task.TaskDescription = title;
            }

            // Add tag(s) to the task
            if (!string.IsNullOrEmpty(addTags))
            {
                addTags = Sanitizer.SanitizeTags(addTags);
                var updatedTags = string.Join(',', task.Tags, addTags);
                updatedTags = Sanitizer.DeduplicateTags(updatedTags);
                task.Tags   = updatedTags[0] == ',' ? updatedTags.Remove(0, 1) : updatedTags;
            }

            // Remove tag(s) from a task
            if (!string.IsNullOrEmpty(removeTags))
            {
                var tagsToRemove = Sanitizer.SanitizeTags(removeTags).Split(',');
                var oldTags      = task.Tags.Split(',');
                task.Tags = string.Join(',', oldTags.Except(tagsToRemove));
            }

            // Remove all tags from a task
            if (resetTags)
            {
                task.Tags = string.Empty;
            }

            _repository.UpdateTask(task);
            var success = _repository.SaveChanges();

            if (success)
            {
                Log.Information($"Successfully updated task : {task.Id} | {task.TaskDescription} | {task.Tags}");
                Output.WriteText($"[green]Successfully updated task[/] : {task.Id} | {task.TaskDescription} | {task.Tags}");
            }
            else
            {
                Log.Error($"Failed to update task [{id}].");
                Output.WriteError($"Failed to update task details. Please try again.");
            }
        }