private static int HandleRemoveTags(IJournalrService service, RemoveTagsOptions opts) { var entry = service.GetEntry(opts.Id); if (string.IsNullOrWhiteSpace(opts.Tags)) { entry.Tags = new List <string>(); } else { var tags = opts.Tags.Split(',').ToList(); entry.Tags = entry.Tags.Where(t => !opts.Tags.Contains(t)).ToList(); } if (service.UpdateEntry(entry)) { Console.WriteLine("Edit successful"); } else { Console.WriteLine("Edit failed"); } return(0); }
private static int HandleEdit(IJournalrService service, EditOptions opts) { var entry = service.GetEntry(opts.Id); if (opts.Body != null) { entry.Text = opts.Body; } if (opts.DateTime != null) { entry.EntryDate = new Chronic.Parser().Parse(opts.DateTime).Start.Value; } if (opts.Tags != null) { var newTags = new List <string>(); foreach (var tag in opts.Tags.Split(',')) { if (!entry.Tags.Contains(tag)) { newTags.Add(tag); } } entry.Tags = newTags; } if (service.UpdateEntry(entry)) { Console.WriteLine("Edit successful"); } else { Console.WriteLine("Edit failed"); } return(0); }