public Task <long> AddAsync(NewTodoItemInfo newTodoItemInfo) { if (newTodoItemInfo == null) { throw new ArgumentNullException(nameof(newTodoItemInfo)); } Validator.ValidateObject(newTodoItemInfo, new ValidationContext(newTodoItemInfo), validateAllProperties: true); return(InternalAddAsync(newTodoItemInfo)); }
private async Task <long> InternalAddAsync(NewTodoItemInfo newTodoItemInfo) { var newTodoItem = new TodoItem(newTodoItemInfo.Name, newTodoItemInfo.Owner.GetName()); if (newTodoItemInfo.IsComplete.HasValue) { newTodoItem.IsComplete = newTodoItemInfo.IsComplete.Value; } await todoDbContext.TodoItems.AddAsync(newTodoItem); await todoDbContext.SaveChangesAsync(); logger.LogInformation("Item with id {TodoItemId} has been added by user [{User}]" , newTodoItem.Id, newTodoItem.CreatedBy); return(newTodoItem.Id); }