public IHttpActionResult PutTodoEntry(int id, TodoEntry todoEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != todoEntry.TodoEntryId) { return(BadRequest()); } db.Entry(todoEntry).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!TodoEntryExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <TodoEntry> AddTodoAsync(TodoEntry todo) { _context.TodoEntries.Add(todo); await _context.SaveChangesAsync(); return(todo); }
public void Update() { // Arrange var todo = new TodoEntry() { OwnerId = 23, IsCompleted = false, Description = "Make a nice cake.", LastUpdated = new DateTime(2012, 12, 12) }; // Act Repository.SaveOrUpdate(todo); todo.OwnerId++; todo.IsCompleted = true; todo.Description = "Eat cake."; todo.LastUpdated = new DateTime(2010, 10, 10); Repository.SaveOrUpdate(todo); // Assert var list = Repository.Select <TodoEntry>(); Assert.AreEqual(1, list.Count); Assert.AreEqual(1, list[0].Id); Assert.AreEqual(24, ((TodoEntry)list[0]).OwnerId); Assert.AreEqual("Eat cake.", ((TodoEntry)list[0]).Description); Assert.AreEqual(true, ((TodoEntry)list[0]).IsCompleted); Assert.AreEqual(new DateTime(2010, 10, 10), ((TodoEntry)list[0]).LastUpdated); }
public async Task <ActionResult <TodoEntry> > PostTodoEntry(TodoEntry todoEntry) { _context.TodoEntries.Add(todoEntry); await _context.SaveChangesAsync(); return(CreatedAtAction("GetTodoEntry", new { id = todoEntry.id }, todoEntry)); }
public async Task <ActionResult <TodoEntryView> > CreateListEntry( [FromRoute] Guid id, [FromBody] ListEntryCreate entry) { var list = await db.Lists.FindAsync(id); if (list == null || list.Owner.Id != AuthorizedUser.Id) { return(NotFound()); } if (string.IsNullOrEmpty(entry.Content)) { return(BadRequest("content value can not be null or empty")); } var createdEntry = new TodoEntry() { Content = entry.Content, Checked = entry.Checked ?? false, ContainedIn = list, }; db.Add(createdEntry); await db.SaveChangesAsync(); return(Created( $"/api/lists/{list.Id}/entries/{createdEntry.Id}", new TodoEntryView(createdEntry))); }
public void TodoEntryStoresInputText() { const string cEntryText = "This is a log entry"; TodoEntry entry = new TodoEntry(cEntryText); Assert.AreEqual(cEntryText, entry.Text); }
public TodoEntryView( TodoEntry entry, bool displayContainedList = true, bool displayContainedListOwner = true) : base(entry) { ContainedIn = displayContainedList ? new TodoListView(entry.ContainedIn, displayContainedListOwner) : null; Content = entry.Content; Checked = entry.Checked; }
public ActionResult <TodoEntry> Post([FromBody] TodoEntry model) { var serviceResult = _todoEntryService.Create(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } return(serviceResult.Model); }
public IHttpActionResult GetTodoEntry(int id) { TodoEntry todoEntry = db.TodoEntries.Find(id); if (todoEntry == null) { return(NotFound()); } return(Ok(todoEntry)); }
public IHttpActionResult PostTodoEntry(TodoEntry todoEntry) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.TodoEntries.Add(todoEntry); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = todoEntry.TodoEntryId }, todoEntry)); }
public async Task <IActionResult> CreateAsync([FromRoute] TodoEntry todo) { try { var addedTodo = await _service.AddTodoAsync(todo); return(Ok(addedTodo)); } catch (Exception) { return(BadRequest()); } }
public IHttpActionResult DeleteTodoEntry(int id) { TodoEntry todoEntry = db.TodoEntries.Find(id); if (todoEntry == null) { return(NotFound()); } db.TodoEntries.Remove(todoEntry); db.SaveChanges(); return(Ok(todoEntry)); }
public void InsertTodo(int Id, string Title, string Text, string LastModified, string Category) { var cat = db.Categories.Single(x => x.Name == Category); TodoEntry newTodo = new TodoEntry() { Title = Title, Text = Text, LastModified = DateTime.Now, Category = cat }; db.Todos.Add(newTodo); db.SaveChanges(); }
public IEnumerable <TodoDetails> Create([FromBody] TodoItem item) { var user = CommonCode.GetCurrentUser(Request); if (user.IsAuthenticated && item != null) { var todoEntry = new TodoEntry() { Description = HttpUtility.HtmlEncode(item.Description), IsCompleted = item.IsCompleted, LastUpdated = DateTime.Now, OwnerId = user.UserId }; Repository.SaveOrUpdate(todoEntry); } return(All()); }
private List <TodoEntry> Grab_Entries() { List <TodoEntry> entries = new List <TodoEntry>(); db.Open(); SqliteCommand selectCommand = new SqliteCommand("SELECT Title_Entry, Content_Entry, Ticks_Entry, Id, Done from TodoList;", db); SqliteDataReader query; try { query = selectCommand.ExecuteReader(); } catch (SqliteException error) { System.Diagnostics.Debug.WriteLine(error); return(entries); } while (query.Read()) { TodoEntry tmpEntry = new TodoEntry(); tmpEntry.title = query.GetString(0); tmpEntry.content = query.GetString(1); System.Diagnostics.Debug.WriteLine(query.GetInt64(2)); tmpEntry.date = new DateTimeOffset(new DateTime(query.GetInt64(2))); tmpEntry.id = query.GetInt16(3); if (query.GetInt16(4) == 0) { tmpEntry.done = ""; } else { tmpEntry.done = "DONE"; } entries.Add(tmpEntry); if (firstQuerry) { onGoing.Add(tmpEntry.id, query.GetInt16(4)); count = tmpEntry.id; } } if (firstQuerry) { count++; } db.Dispose(); firstQuerry = false; return(entries); }
public ActionResult <TodoEntry> Delete(int id) { var model = new TodoEntry() { TodoEntryId = id }; var serviceResult = _todoEntryService.Delete(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } return(serviceResult.Model); }
public ActionResult <TodoEntry> Put(int id, [FromBody] TodoEntry model) { model.TodoEntryId = id; var serviceResult = _todoEntryService.Update(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } if (serviceResult.Status == BrashActionStatus.NOT_FOUND) { return(NotFound(serviceResult.Message)); } return(serviceResult.Model); }
public ActionResult <TodoEntry> Get(int id) { var model = new TodoEntry() { TodoEntryId = id }; var serviceResult = _todoEntryService.Fetch(model); if (serviceResult.Status == BrashActionStatus.ERROR) { return(BadRequest(serviceResult.Message)); } if (serviceResult.Status == BrashActionStatus.NOT_FOUND) { return(NotFound(serviceResult.Message)); } return(serviceResult.Model); }
public void DisplayTodoHeaderStateOutputsAllTodoItems() { TodoEntry todoEntry = new TodoEntry("entry"); List <TodoEntry> todoEntries = new List <TodoEntry>() { todoEntry }; IConsole mockConsole = Substitute.For <IConsole>(); ILog mockLog = Substitute.For <ILog>(); ITodoList mockTodoList = Substitute.For <ITodoList>(); mockTodoList.GetEntries().Returns(todoEntries); DisplayTodoListHeaderState state = new DisplayTodoListHeaderState(mockConsole, mockLog, mockTodoList); state.Execute(); mockConsole.Received(1).Output("0> "); mockConsole.Received(1).OutputLine("entry"); }
public async Task <IActionResult> PutTodoEntry(int id, TodoEntry todoEntry) { todoEntry.id = id; _context.Entry(todoEntry).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TodoEntryExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void CreateUpdateDeleteFetch() { // file system var path = "/shop/randomsilo/modern-web/backends/TodoList"; var project = "TodoList"; var outputPath = $"{path}/{project}.Infrastructure.Test/TestOutput/"; var databaseFile = GetDatabase(outputPath, MethodBase.GetCurrentMethod()); // logger ILogger logger = GetLogger($"{outputPath}/{MethodBase.GetCurrentMethod().ReflectedType.Name}_{MethodBase.GetCurrentMethod().Name}.log"); // database setup // - context IDatabaseContext databaseContext = new DatabaseContext( $"Data Source={databaseFile}" , "TestDb" , "TestSchema" , $"{path}/sql/sqlite/ALL.sql" ); Assert.NotNull(databaseContext); // - manager IManageDatabase databaseManager = new DatabaseManager(databaseContext); Assert.NotNull(databaseManager); // - create tables databaseManager.CreateDatabase(); // - repository var todoEntryRepository = new TodoEntryRepository(databaseManager, new TodoEntryRepositorySql(), logger); Assert.NotNull(todoEntryRepository); // faker BrashActionResult <TodoEntry> result = null; var todoEntryFaker = new TodoEntryFaker(databaseManager, logger); Assert.NotNull(todoEntryFaker); // create var todoEntryCreateModel = todoEntryFaker.GetOne(); result = todoEntryRepository.Create(todoEntryCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.TodoEntryId > 0); // use model with id todoEntryCreateModel = result.Model; // update var todoEntryUpdateModel = todoEntryFaker.GetOne(); todoEntryUpdateModel.TodoEntryId = todoEntryCreateModel.TodoEntryId; result = todoEntryRepository.Update(todoEntryUpdateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // delete result = todoEntryRepository.Delete(todoEntryCreateModel); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); // fetch // - make fakes var fakes = todoEntryFaker.GetMany(10); // - add fakes to database List <int?> ids = new List <int?>(); foreach (var f in fakes) { result = todoEntryRepository.Create(f); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.TodoEntryId >= 0); ids.Add(result.Model.TodoEntryId); } // - get fakes from database foreach (var id in ids) { var model = new TodoEntry() { TodoEntryId = id }; result = todoEntryRepository.Fetch(model); Assert.True(result.Status == BrashActionStatus.SUCCESS, result.Message); Assert.True(result.Model.TodoEntryId >= 0); } }
public BrashActionResult <TodoEntry> Fetch(TodoEntry model) { return(Repository.Fetch(model)); }
public BrashActionResult <TodoEntry> Delete(TodoEntry model) { return(Repository.Delete(model)); }
public void TodoEntryThrowsExceptionWhenGivenEmptyText() { TodoEntry entry = new TodoEntry(""); }
public void TodoEntryThrowsExceptionWhenGivenNullText() { TodoEntry entry = new TodoEntry(null); }
public async Task <TodoEntry> AddTodoAsync(TodoEntry todo) { return(await _repository.AddTodoAsync(todo)); }