public async Task <ToDoItem> UpdateToDoItem(ToDoItem newItem)
        {
            var item = ToDoItemConverter.ToDbToDoItem(newItem);
            var resp = await ListsRepository.EditToDoItem(item);

            return(ToDoItemConverter.ToDomainToDoItem(resp));
        }
        public IActionResult GetDoneTodoItems()
        {
            List <ToDoItemModel> todoItems = new List <ToDoItemModel>();

            foreach (var item in dbContext.ToDoItems.Where(n => n.IsDone))
            {
                todoItems.Add(ToDoItemConverter.FromEntityToModel(item));
            }

            return(Ok(todoItems));
        }
        public async Task <ToDoItem> AddToDoItem(string newItem, string travelIdentity)
        {
            var toDoItem = new DbToDoItem
            {
                Id      = Guid.NewGuid().ToString(),
                Name    = newItem,
                Checked = false
            };
            var addedItem = await ListsRepository.AddToDoItem(toDoItem, travelIdentity);

            return(ToDoItemConverter.ToDomainToDoItem(addedItem));
        }
        public IActionResult List()
        {
            List <ToDoItemModel> todoItems = new List <ToDoItemModel>();

            logger.LogInformation($"# of PomodoreItems: {dbContext.PomodoroItems.ToList().Count}");
            logger.LogInformation($"# of todoItems: {dbContext.ToDoItems.ToList().Count}");

            foreach (var item in dbContext.ToDoItems.Where(n => !n.IsDone))
            {
                todoItems.Add(ToDoItemConverter.FromEntityToModel(item));
            }

            return(Ok(todoItems));
        }
        public IActionResult TodoItemDone([FromBody] Guid doneTodoGuid)
        {
            var todoItemToUpdate = dbContext.ToDoItems.Where(n => n.Id == doneTodoGuid).FirstOrDefault();

            if (todoItemToUpdate != null)
            {
                todoItemToUpdate.IsDone       = true;
                todoItemToUpdate.FinishedDate = DateTime.UtcNow;

                dbContext.SaveChanges();
                return(Ok(ToDoItemConverter.FromEntityToModel(todoItemToUpdate)));
            }

            return(BadRequest($"In {nameof(TodoItemDone)}, error setting IsDone for {doneTodoGuid}"));
        }
        public IActionResult AddNewTodoItem([FromBody] ToDoItemModel item)
        {
            try
            {
                if (item == null || !ModelState.IsValid)
                {
                    return(BadRequest("Invalid State"));
                }

                var savedItem = dbContext.ToDoItems.Add(ToDoItemConverter.FromModelToEntity(item));
                dbContext.SaveChanges();
                var retItem = ToDoItemConverter.FromEntityToModel(savedItem.Entity);

                return(Ok(retItem));
            }
            catch (Exception e)
            {
                logger.LogWarning($"{nameof(AddNewTodoItem)} failed, {e?.GetType()}, msg: {e?.Message}");
                return(BadRequest("Error while creating"));
            }
        }
        public async Task <ToDoItem[]> GetToDoItems(string travelIdentity)
        {
            var items = await ListsRepository.GetToDoItems(travelIdentity);

            return(items.Select(i => ToDoItemConverter.ToDomainToDoItem(i)).ToArray());
        }