Example #1
0
 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;
 }
Example #2
0
        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);
        }
Example #3
0
        public void MarkTodoElementAsDone(int id, string description)
        {
            var element = new TodoElement(id, description);

            element.MarkAsDone();

            Assert.NotNull(element);
            Assert.IsTrue(element._done);
        }
Example #4
0
        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());
            }
        }
Example #8
0
 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;
 }
Example #9
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();
         }
     }
 }
Example #10
0
 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;
 }
Example #11
0
 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;
 }
Example #12
0
        public void CreateTodoElement(int id, string description)
        {
            var element = new TodoElement(id, description);

            Assert.NotNull(element);
        }
Example #13
0
        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());
        }