示例#1
0
        public IActionResult UpdateCheckbox([FromBody] TodoChecklist checklist)
        {
            var oldCheckList = _todoCheckLists.GetById(checklist.Id);

            if (oldCheckList == null)
            {
                return(NotFound());
            }

            foreach (var oldItem in oldCheckList.CheckList)
            {
                foreach (var item in checklist.CheckList)
                {
                    if (oldItem.Id != item.Id)
                    {
                        continue;
                    }
                    oldItem.Text    = item.Text;
                    oldItem.Checked = item.Checked;
                }
            }
            oldCheckList.LastEdit = DateTime.Now;
            oldCheckList.Title    = checklist.Title;

            _todoCheckLists.Update(oldCheckList);
            return(Ok());
        }
示例#2
0
        public IActionResult CreateChecklist()
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var todoChecklist = new TodoChecklist
            {
                Title     = "TODO",
                Created   = DateTime.Now,
                LastEdit  = DateTime.Now,
                CheckList = new List <TodoCheckListItem>
                {
                    new TodoCheckListItem
                    {
                        Checked = false,
                        Text    = "Placeholder"
                    }
                }
            };

            _todoCheckLists.Add(todoChecklist);
            return(Ok(Json(todoChecklist)));
        }