private void FullFill(TodoElement result, SqlDataReader reader) { result.Id = HasColumn(reader, "Id") ? Convert.ToInt32(reader["Id"]) : 0; result.Name = HasColumn(reader, "TodoName") ? (string)reader["TodoName"] : ""; result.Content = HasColumn(reader, "Content") ? (string)reader["Content"] : ""; result.Checked = HasColumn(reader, "Done") ? Convert.ToBoolean(reader["Done"]) : false; }
public void CreateTodoElementCheckCorrectness(int id, string description) { var element = new TodoElement(id, description); Assert.NotNull(element); StringAssert.AreEqualIgnoringCase(description, element._description); Assert.AreEqual(id, element._id); }
public void MarkTodoElementAsDone(int id, string description) { var element = new TodoElement(id, description); element.MarkAsDone(); Assert.NotNull(element); Assert.IsTrue(element._done); }
public void CreateTodoElementRestoreStateConstructur(int id, string description, bool done) { var element = new TodoElement(id, description, done); Assert.NotNull(element); StringAssert.AreEqualIgnoringCase(description, element._description); Assert.AreEqual(id, element._id); Assert.AreEqual(done, element._done); }
public async Task <ActionResult <int> > Create(TodoElement todo) { try { int result = await sqlService.Create(todo); return(todo.Id); } catch (Exception) { return(NotFound()); } }
public async Task <ActionResult <TodoElement> > Details(int id) { try { TodoElement result = await sqlService.Get(id); return(result); } catch (Exception) { return(NotFound()); } }
public async Task <ActionResult> Edit(TodoElement todo) { try { await sqlService.Edit(todo); return(Ok()); } catch (Exception) { return(NotFound()); } }
public async Task<int> Create(TodoElement todo) { using (SqlConnection connection = await GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "INSERT INTO Todo(TodoName, Done, Content) VALUES (@Name, @Checked, @Content)"; cmd.Parameters.AddWithValue("@Name", todo.Name); cmd.Parameters.AddWithValue("@Checked", todo.Checked); cmd.Parameters.AddWithValue("@Content", todo.Content); cmd.ExecuteNonQuery(); } } return 0; }
public async Task Edit(TodoElement todo) { using (SqlConnection connection = await GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "UPDATE Todo SET Done = @checked, TodoName = @name, Content = @content WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", todo.Id); cmd.Parameters.AddWithValue("@name", todo.Name); cmd.Parameters.AddWithValue("@checked", todo.Checked); cmd.Parameters.AddWithValue("@content", todo.Content); cmd.ExecuteNonQuery(); } } }
public async Task<TodoElement> Get(int id) { TodoElement result = new TodoElement(); using (SqlConnection connection = await GetConnection()) { using (SqlCommand cmd = connection.CreateCommand()) { cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "SELECT Id, TodoName, Content, Done FROM Todo WHERE Id = @id"; cmd.Parameters.AddWithValue("@id", id); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { FullFill(result, reader); } } } } return result; }
public async Task<List<TodoElement>> Get() { List<TodoElement> result = new List<TodoElement>(); using(SqlConnection connection = await GetConnection()) { using(SqlCommand cmd = connection.CreateCommand()) { cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = "SELECT Id, TodoName, Content, Done FROM Todo"; using(SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { TodoElement todo = new TodoElement(); FullFill(todo, reader); result.Add(todo); } } } } return result; }
public void CreateTodoElement(int id, string description) { var element = new TodoElement(id, description); Assert.NotNull(element); }
public async Task <ActionResult <TodoElement> > UpdateListElementAsync(int id, [FromBody] TodoElement element) { var current = await _context.TodoLists.GetAsync(id, s => s.Items); if (current == null) { return(NotFound()); } if (id != DefaultList.id) { // if default list is being updated, no need to adjust other lists positions var lists = await _context.TodoLists.GetAsync(l => l.Id != DefaultList.id); PositionAdjuster.AdjustForUpdate(element, lists.ToList <ISortable>(), current); } current.UpdateFrom(element); _context.TodoLists.Update(current); await _context.SaveChangesAsync(); return(current.ToElement()); }