public EditTodoNoteViewModel(TodoNote todoNote) { this.TodoNote = todoNote; //foreach(TodoNote.TodoEntry entry in TodoNote.TodoEntries){ // this.todoEntries.Add(new TodoEntry(entry.ID, entry.Content, entry.IsDone)); //} }
public void DeleteTodo() { List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a delete test!"; string testString2 = "This is also a delete test!"; addObject.AddTask(testString, "Test.json"); addObject.AddTask(testString2, "Test.json"); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int sizeBeforeDelete = todoList.Count; TodoNote temp = new TodoNote(); temp.DeleteTask(1, "Test.json"); List <TodoNote> newTodoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int sizeAfterDelete = newTodoList.Count; // The new size of the list should match the old size -1 Assert.Equal(sizeBeforeDelete - 1, sizeAfterDelete); }
public async Task <IActionResult> PutTodoNote([FromRoute] int id, [FromBody] TodoNote todoNote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != todoNote.Id) { return(BadRequest()); } _context.Entry(todoNote).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoNoteExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task GetByPageWorksAsync() { var note = new TodoNote { Note = "testingEarly" }; var todoEarly = new Todo(note); await m_controller.DataLayer.InsertAsync(todoEarly); await Task.Delay(1000); note = new TodoNote { Note = "testingLate" }; var todoLate = new Todo(note); await m_controller.DataLayer.InsertAsync(todoLate); var actionResult = await m_controller.GetAsync(1, 1); var contentResult = actionResult as OkNegotiatedContentResult <PagedTodos>; Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(todoEarly.Id, contentResult.Content.Items.First().Id); Assert.AreEqual(todoEarly.Note, contentResult.Content.Items.First().Note); Assert.IsNull(contentResult.Content.NextPageLink); }
private void UpdateNote(long noteId, string title, ObservableCollection <TodoNote.TodoEntry> TodoEntries) { string timeStamp = TimeUtil.GetStringTimestamp(); ISQLiteStatement statement = dbConn.Prepare(UPDATE_TODO_NOTE); statement.Bind(1, title); statement.Bind(2, timeStamp); statement.Bind(3, null); statement.Bind(4, noteId); statement.Step(); TodoNote todoNote = (TodoNote)GetNoteById(noteId); // Delete all todo note contents foreach (TodoNote.TodoEntry entry in ((TodoNote)GetNoteById(noteId)).TodoEntries) { statement.Reset(); statement.ClearBindings(); statement = dbConn.Prepare(DELETE_TODO_NOTE_CONTENT); statement.Bind(1, entry.Id); statement.Step(); } // Add all todo note new contents foreach (TodoNote.TodoEntry entry in TodoEntries) { statement.Reset(); statement.ClearBindings(); statement = dbConn.Prepare(INSERT_TODO_NOTE_CONTENT); statement.Bind(1, entry.Content); statement.Bind(2, ConvertBoolToInt(entry.IsDone)); statement.Bind(3, noteId); statement.Bind(4, timeStamp); statement.Step(); } }
static void Main(string[] args) { Console.WriteLine("Welcome to this TODO application!"); Console.WriteLine("Commands supported: Add 'Your task'/ Do #TaskNumber / Print -> Prints all items!"); Console.WriteLine("Type 'quit' to exit the application"); string path = "todoList.json"; bool quitApplication = false; while (!quitApplication) { quitApplication = true; string userInput = Console.ReadLine(); string[] wordSplit = userInput.Split(" ", 2); string inputCommand = wordSplit[0]; // Close application if input = q quitApplication = (string.Compare(inputCommand.ToLower(), "quit") == 0) ? true : false; if (quitApplication) { break; } // Removes type sensitive input and compares input if (string.Compare(inputCommand.ToLower(), "add") == 0) { string inputText = wordSplit[1]; TodoNote newTask = new TodoNote(); newTask.AddTask(inputText, path); } else if (string.Compare(inputCommand.ToLower(), "print") == 0) { TodoNote newTask = new TodoNote(); newTask.ShowAllTasks(); } else if (string.Compare(inputCommand.ToLower(), "do") == 0) { string convertNumber = wordSplit[1]; int number; if (int.TryParse(convertNumber, out number)) { TodoNote newTask = new TodoNote(); newTask.DeleteTask(number, path); } else { Console.WriteLine("Something went wrong! Try again: Do <int>"); } } else { Console.WriteLine("Unknown command: {0}", userInput); } } }
public async Task <IActionResult> PostTodoNote([FromBody] TodoNote todoNote) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.TodoNotes.Add(todoNote); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoNote", new { id = todoNote.Id }, todoNote)); }
public BaseNote GetNoteById(long id) { TodoNote todoNote = (TodoNote)databaseHelper.GetNoteById(id); if (todoNote.ScheduledNotification != null && todoNote.ScheduledNotification.Date.Add(todoNote.ScheduledNotification.Time) < DateTimeOffset.Now) { Debug.WriteLine("Notification too old..deleting"); this.DeleteNotification(id); todoNote.ScheduledNotification = null; } return(databaseHelper.GetNoteById(id)); }
public async Task UpdateNonExistentIsBadRequestAsync() { var note = new TodoNote { Note = "testing" }; var todo = new Todo(note); var actionResult = await m_controller.PutAsync(todo); var badRequestResult = actionResult as BadRequestErrorMessageResult; Assert.IsNotNull(badRequestResult); Assert.IsNotNull(badRequestResult.Message); }
public async Task DeleteWorksAsync() { var note = new TodoNote { Note = "testing" }; var todo = new Todo(note); await m_controller.DataLayer.InsertAsync(todo); var actionResult = await m_controller.DeleteAsync(todo.Id); var okResult = actionResult as OkResult; Assert.IsNotNull(okResult); }
public async Task InsertWorksAsync() { var note = new TodoNote { Note = "testing" }; var actionResult = await m_controller.PostAsync(note); var createdResult = actionResult as CreatedAtRouteNegotiatedContentResult <Todo>; Assert.IsNotNull(createdResult); Assert.AreEqual("DefaultApi", createdResult.RouteName); Assert.AreNotEqual(Guid.Empty, createdResult.RouteValues["id"]); Assert.AreNotEqual(Guid.Empty, createdResult.Content.Id); Assert.AreNotEqual(new DateTime().Ticks, createdResult.Content.DateTime.Ticks); }
public IActionResult UpdateNote([FromBody] TodoNote todoNote) { var oldNote = _todoNotes.GetById(todoNote.Id); if (oldNote == null) { return(NotFound()); } oldNote.LastEdit = DateTime.Now; oldNote.Title = todoNote.Title; oldNote.Note = todoNote.Note; _todoNotes.Update(oldNote); return(Ok()); }
public async Task GetByIdWorksAsync() { var note = new TodoNote { Note = "testing" }; var todo = new Todo(note); await m_controller.DataLayer.InsertAsync(todo); var actionResult = await m_controller.GetAsync(todo.Id); var contentResult = actionResult as OkNegotiatedContentResult <Todo>; Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(todo.Id, contentResult.Content.Id); Assert.AreEqual(todo.Note, contentResult.Content.Note); }
public IActionResult CreateNote() { if (!ModelState.IsValid) { return(BadRequest()); } var todoNote = new TodoNote { Title = "TODO", Created = DateTime.Now, LastEdit = DateTime.Now, Note = "Placeholder" }; _todoNotes.Add(todoNote); return(Ok(Json(todoNote))); }
public void DeleteNote(long id) { ISQLiteStatement statement = dbConn.Prepare(DELETE_TODO_NOTE_CONTENT); TodoNote todoNote = (TodoNote)GetNoteById(id); foreach (TodoNote.TodoEntry entry in todoNote.TodoEntries) { statement.Bind(1, entry.Id); statement.Step(); statement.Reset(); statement.ClearBindings(); } statement = dbConn.Prepare(DELETE_TODO_NOTE); statement.Bind(1, id); statement.Step(); DeleteNotificationByNoteId(id); }
public void UpdateNoteAndNotification(long noteId, string title, ObservableCollection <TodoNote.TodoEntry> TodoEntries, string schedulingId, DateTimeOffset dateTime) { TodoNote note = (TodoNote)GetNoteById(noteId); long notificationId; if (note.ScheduledNotification != null) { Debug.WriteLine("Updating notification with id : " + note.ScheduledNotification.DataBaseId); NotificationHelper.UpdateNotification(note.ScheduledNotification.DataBaseId, schedulingId, dateTime); notificationId = note.ScheduledNotification.DataBaseId; } else { notificationId = NotificationHelper.AddNotification(schedulingId, dateTime); } UpdateNote(noteId, title, TodoEntries, notificationId); }
// Test adding to a empty Json file public void TestAddEmptyJsonFile() { // Start with a empty test List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a test string!"; addObject.AddTask(testString, "Test.json"); TodoNote temp = new TodoNote(); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int lastTodo = todoList.Count; string containedString = todoList[0].task; // The first object should be printed as the first position Assert.Equal(testString, containedString); }
public void TestAppendToJsonFile() { List <TodoNote> updateList = new List <TodoNote>(); HandleJson.WriteToJsonFile <List <TodoNote> >("Test.json", updateList); TodoNote addObject = new TodoNote(); string testString = "This is a new test!"; string testString2 = "Append to the now test!"; addObject.AddTask(testString, "Test.json"); addObject.AddTask(testString2, "Test.json"); TodoNote temp = new TodoNote(); List <TodoNote> todoList = HandleJson.ReadFromJsonFile <List <TodoNote> >("Test.json"); int lastTodo = todoList.Count; string expectTest2 = todoList[lastTodo - 1].task; // Last TODO object should be the last element Assert.Equal(testString2, expectTest2); }
public async Task <IHttpActionResult> PostAsync(TodoNote note) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } do { try { var todo = new Todo(note); await DataLayer.InsertAsync(todo); return(CreatedAtRoute("DefaultApi", new { id = todo.Id }, todo)); } catch (DataLayerAlreadyExistsException) { // generate a new Id continue; } } while (true); }
public EditTodoNoteViewModel() { this.TodoNote = new TodoNote(); }
public void DeleteTodoNote(TodoNote todoNote) { _context.TodoNotes.Remove(todoNote); }
public void AddNoteToTodo(Guid todoId, TodoNote todoNote) { var todo = GetTodo(todoId); todo.Notes.Add(todoNote); }