public EitherAsync <DatabaseFailure, Unit> Update(TodoItemDto todoItem) => TryAsync(() => _todoCollection.UpdateOneAsync(x => x.Id == todoItem.Id, Updater(todoItem)).ToUnit()) .ToEither() .MapLeft(DatabaseFailureCon.Update);
private static UpdateDefinition <TodoItemDto> Updater(TodoItemDto dto) => Builders <TodoItemDto> .Update .Set(x => x.Content, dto.Content) .Set(x => x.IsDone, dto.IsDone);
public EitherAsync <DatabaseFailure, Unit> Add(TodoItemDto todoItem) => TryAsync(() => _todoCollection.InsertOneAsync(todoItem).ToUnit()) .ToEither() .MapLeft(DatabaseFailureCon.Insert);